Found 190 Articles for Selenium Web Driver

How to read a text file in Selenium with python?

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

2K+ 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

How to close a 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

How to perform back and refresh in a browser in Selenium with python?

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

511 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

How to get the title and URL of the page in Selenium with python?

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

1K+ 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

How to maximize and minimize browsers in Selenium with python?

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

2K+ 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

How to invoke the IE browser in Selenium with python?

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

824 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

How to invoke the 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

How to invoke the Chrome browser in Selenium with python?

Debomita Bhattacharjee
Updated on 29-Jul-2020 06:51:59

12K+ 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 chrome browser, we have to select the Chrome class. Then create the driver object of that class. This is the most important and mandatory step for browser invocation.Every chrome 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 the ... Read More

How to identify multiple elements at the same time in Selenium with python?

Debomita Bhattacharjee
Updated on 28-Jul-2020 15:38:55

669 Views

We can locate and identify multiple elements at the same time in Selenium. There are various strategies to locate the elements. The different ways of locating elements are listed below −find_elements_by_xpath – This method returns all the elements with matching xpath in the argument in form a list. It shall return an empty list if no element has the matching xpath.Syntaxdriver.find_elements_by_xpath("//input[name='text-search']")find_elements_by_link_text – This method returns all the elements with matching value of link text in the argument to form a list. It shall return an empty list if no element has the matching text.Syntaxdriver.find_elements_by_link_text("Tutorialspoint")find_elements_by_name – This method returns all the ... Read More

What are the differences between implicit and explicit waits in Selenium with python?

Debomita Bhattacharjee
Updated on 28-Jul-2020 15:28:16

10K+ Views

The differences between implicit and explicit wait are listed below −Implicit WaitExplicit Wait1The driver is asked to wait for a specific amount of time for the element to be available on the DOM of the page.The driver is asked to wait till a certain condition is satisfied.2It is a global wait and applied to all elements on the webpage.It is not a global wait and applied to a particular scenario.3It does not require you to meet any condition.It is required to satisfy a particular condition. Some of the expected conditions include −title_containsvisibility_of_element_locatedpresence_of_element_locatedtitle_isvisibility_ofelement_selection_state_to_bepresence_of_all_elements_locatedelement_located_to_be_selectedalert_is_presentelement_located_selection_state_to_b estaleness_ofelement_to_be_clickableinvisibility_of_element_locatedframe_to_be_available_and_switch_to _ittext_to_be_present_in_element_valuetext_to_be_present_in_elementelement_to_be_selected4Syntaxdriver.implicitly_wait(2)Syntaxw = WebDriverWait(driver, 7) w.until(expected_conditions.presence_of_ele ment_located((By.ID, "Tutorialspoint")))5It ... Read More

Advertisements