How can I write test scripts in Selenium with python

0 votes
Anyone please suggest how can I write Test Scripts in Selenium with Python?
May 9, 2019 in Selenium by Khushi
651 views

1 answer to this question.

0 votes

Hey Khushi, writing test scripts in Selenium with Python is almost similar to writing scripts in Java, except for the syntax. Below is a code snippet of test Script written in Python testing the Login functionality of Facebook:

'''
Created on 09-May-2019

@author: Anvi_R
'''

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome("C:\\\\Users\\\\Abha_Rathour\\\\Downloads\\\\ExtractedFiles\\\\chromedriver_win32\\\\chromedriver.exe")
driver.maximize_window()
driver.implicitly_wait(3)
driver.get("http://www.facebook.com")
assert "Facebook" in driver.title
driver.find_element_by_id("email").send_keys("username")
driver.find_element_by_id("pass").send_keys("password")
driver.find_element_by_id("u_0_8").click()
driver.close()

Here, I have used driver.implicitly_wait(time_in_seconds) to let the driver load all the web elements, so that elements can be located easily. 

answered May 9, 2019 by Anvi
• 14,150 points

Related Questions In Selenium

+2 votes
2 answers

How can I press ENTER key with the execute_script in selenium python?

The below code containing Keys.ENTER might just ...READ MORE

answered Mar 28, 2018 in Selenium by nsv999
• 5,500 points
26,663 views
+1 vote
2 answers

How can I delete an element in Selenium using Python?

You can directly delete the node using ...READ MORE

answered Sep 14, 2019 in Selenium by tonystark
• 500 points
18,845 views
0 votes
1 answer

How can I add Cucumber Jar files in Eclipse to use with Selenium Webdriver?

Hey Eshan, follow these steps to add ...READ MORE

answered May 23, 2019 in Selenium by Abha
• 28,140 points
5,592 views
0 votes
1 answer
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
12,714 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,608 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
6,681 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,551 views
0 votes
1 answer

How can I create a POM test case in Selenium Webdriver?

Hey Akshay, follow these steps to create ...READ MORE

answered May 13, 2019 in Selenium by Anvi
• 14,150 points
1,219 views
0 votes
1 answer

How to create a Base Class in Selenium and use it with test scripts?

Hi Donna, you can use following code ...READ MORE

answered Jul 18, 2019 in Selenium by Anvi
• 14,150 points
12,062 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP