Different Locators Used in Selenium with Python

Debomita Bhattacharjee
Updated on 29-Jul-2020 07:21:40

176 Views

The different locators used in Selenium with python are listed below.Id - The element is identified with its id attribute. NoSuchElementException raised if element with matching id is not available.Syntax −driver.find_element_by_id("id")Name - The element is identified with its name attribute. NoSuchElementException raised if element with matching name is not available.Syntax −driver.find_element_by_name("name")Xpath - The element is identified with the attributes and tagname. There are two types of xpath – absolute and relative.Syntax −driver.find_element_by_xpath("//input[@type='type']")CSS - The element is identified with the help of css expression built with the help of attributes like id, class and tagName. NoSuchElementException raised if element with matching ... Read More

Write a Text File in Selenium with Python

Debomita Bhattacharjee
Updated on 29-Jul-2020 07:19:15

2K+ Views

We can write a text file in Selenium with python by first creating a txt file and having a content on it.First of all, we need to open the file in write mode and mention the path of the location of the text file as an argument. There are multiple reading methods to perform these operations.write() – It writes the string in one line in a text file.writelines() – It writes more than one string in a text file.ExampleCode Implementation with write().#open the file for write operation f = open('hello.txt' , 'w') #writes the new content f.write('Tutorialspoint') #close the file ... Read More

Differences Between readline and readlines in Selenium with Python

Debomita Bhattacharjee
Updated on 29-Jul-2020 07:15:42

11K+ Views

The differences between readline() and readlines() methods are listed below.readlines()This method will read the entire content of the file at a time.This method reads all the file content and stores it in the list.This method reads up to the end of the line with readline () and returns a list.readline()This method will read one line in a file.A new line character is left at the string end and is ignored for the last line provided the file does not finish in a new line.This method reads up to the end of the line with readline() and returns a list.ExampleCode Implementation ... Read More

Read a Text File in Selenium with Python

Debomita Bhattacharjee
Updated on 29-Jul-2020 07:13:28

3K+ Views

We can read a text file in Selenium with python by first creating a txt file and having a content on it.First of all, we need to open the file and mention the path of the location of the text file as an argument. There are multiple reading methods to perform these operations.read() – It reads the entire content of the file.read(n) – It reads n characters of the text file.readline() – It reads character line by line at a time. If we need to read the first two lines, the readline() method is to be used twice.readlines() – it reads ... Read More

Close Browser Session in Selenium with Python

Debomita Bhattacharjee
Updated on 29-Jul-2020 07:11:39

1K+ Views

We can close a browser session in Selenium by the following ways −Using the close() method.Using the quit() method.Both these methods close the browser, but close() the browser in focus and quit() ends the driver session.ExampleCode Implementation with close().from selenium import webdriver #browser exposes an executable file #Through Selenium test we will invoke the executable file which will then #invoke actual browser driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") # to maximize the browser window driver.maximize_window() #get method to launch the URL driver.get("https://www.tutorialspoint.com/index.htm") #to refresh the browser driver.refresh() #to close the browser driver.close()Code Implementation with quit().from selenium import webdriver #browser exposes an executable file ... Read More

Perform Back and Refresh in a Browser using Selenium with Python

Debomita Bhattacharjee
Updated on 29-Jul-2020 07:09:15

636 Views

We can perform back and refresh in the browser in Selenium.For performing back operation in the browser, the back method is to be used.For refreshing the browser, refresh method is to be used.Both these methods can be used for testing browser navigations and reloading of web pages.ExampleCode Implementationfrom selenium import webdriver #browser exposes an executable file #Through Selenium test we will invoke the executable file which will then #invoke actual browser driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") # to maximize the browser window driver.maximize_window() #get method to launch the URL driver.get("https://www.tutorialspoint.com/index.htm") # to print the page title in console print(driver.title) # to print ... Read More

Get Title and URL of Page in Selenium with Python

Debomita Bhattacharjee
Updated on 29-Jul-2020 07:02:22

2K+ Views

We can get the title and URL of the page in Selenium.For getting the title of the browser, the title method is to be used.For getting the URL of the page, the current_url method is to be used.Both these methods can be used for testing if we are navigated to the correct page and page title.ExampleCode Implementationfrom selenium import webdriver #browser exposes an executable file #Through Selenium test we will invoke the executable file which will then #invoke actual browser driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") # to maximize the browser window driver.maximize_window() #get method to launch the URL driver.get("https://www.tutorialspoint.com/index.htm") # to print ... Read More

Maximize and Minimize Browsers in Selenium with Python

Debomita Bhattacharjee
Updated on 29-Jul-2020 06:58:42

3K+ Views

We can maximize and minimize the browser while we are testing an application in Selenium.For maximizing the browser, maximize() method is to be used.For minimizing the browser, minimize() method is to be used.Both these methods can be used simultaneously in the same program.ExampleCode Implementationfrom selenium import webdriver #browser exposes an executable file #Through Selenium test we will invoke the executable file which will then #invoke actual browser driver = webdriver.Firefox(executable_path="C:\geckodriver.exe") # to maximize the browser window driver.maximize_window() #get method to launch the URL driver.get("https://www.tutorialspoint.com/index.htm") #to refresh the browser driver.refresh() # to minimize the browser window driver.minimize_window() #to close the browser ... Read More

Invoke IE Browser in Selenium with Python

Debomita Bhattacharjee
Updated on 29-Jul-2020 06:57:13

1K+ Views

We can invoke any browsers with the help of the webdriver package. From this package we get access to numerous classes. Next we have to import the selenium.webdriver package. Then we shall be exposed to all the browsers belonging to that package.For invoking the internet explorer browser, we have to select the Ie class. Then create the driver object of that class. This is the most important and mandatory step for browser invocation.Every internet explorer browser gives an executable file. Through Selenium we need to invoke this executable file which is responsible for invoking the actual chrome browser.Next we need ... Read More

Invoke Firefox Browser in Selenium with Python

Debomita Bhattacharjee
Updated on 29-Jul-2020 06:55:40

3K+ Views

We can invoke any browsers with the help of the webdriver package. From this package we get access to numerous classes. Next we have to import the selenium.webdriver package. Then we shall be exposed to all the browsers belonging to that package.For invoking the Firefox browser, we have to select the Firefox class. Then create the driver object of that class. This is the most important and mandatory step for browser invocation.Every firefox browser gives an executable file. Through Selenium we need to invoke this executable file which is responsible for invoking the actual chrome browser.Next we need to download ... Read More

Advertisements