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 in Selenium by Khushi
29 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 by Anvi
• 10,830 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 27, 2018 in Selenium by nsv999
• 5,050 points
5,141 views
0 votes
1 answer

How can I delete an element in Selenium using Python?

Hi friend, getElementByClassName is not a method on ...READ MORE

answered Mar 26 in Selenium by Surya
• 990 points

edited Mar 27 by Omkar 373 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

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,050 points
280 views
0 votes
1 answer
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,130 points
641 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
269 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 12 in Selenium by Anvi
• 10,830 points
36 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 5 days ago in Selenium by Anvi
• 10,830 points
16 views