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
11 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
• 5,880 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,030 points
3,974 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
• 780 points

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

Can anyone help me that how to run Selenium WebDriver test cases in Chrome?

Download the executable driver from: ChromeDriver Download Before ...READ MORE

answered Mar 29, 2018 in Selenium by nsv999
• 5,030 points
121 views
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,030 points
65 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
438 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
51 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
• 5,880 points
16 views
0 votes
1 answer

How can I use HTML Unit Driver as a headless browser with Selenium?

Hello @Nishant, follow these steps to use ...READ MORE

answered 6 days ago in Selenium by Anvi
• 5,880 points
5 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.