Found 466 Questions for Selenium

How to get text with selenium web driver in python?

Debomita Bhattacharjee
Updated on 28-Aug-2020 12:37:27
We can extract text of an element with a selenium webdriver. This is done with the help of a text method. It fetches the text in an element which can be later validated.First we need to identify the element with the help of any locators. Suppose we want to get the text of an element in below page.ExampleCode Implementation.from selenium import webdriver driver = webdriver.Chrome (executable_path="C:\chromedriver.exe") # maximize with maximize_window() driver.maximize_window() driver.get("https://www.tutorialspoint.com/index.htm") # identify element l=driver.find_element_by_css_selector("h4") # get text and print print("Text is: " + l.text) driver.close()OutputRead More

Getting the URL of the current page using Selenium WebDriver.

Debomita Bhattacharjee
Updated on 28-Aug-2020 12:35:45
We can obtain the URL of the current page with Selenium webdriver. This is achieved with the help of getCurrentUrl() method. It fetches the URL of the opened application. This method accepts no parameters and strings the URL in the form of String.Syntax −String strUrl = driver.getCurrentUrl();ExampleCode Implementation.import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class CurrentUrl{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String url = "https://www.tutorialspoint.com/index.htm";       driver.get(url);       driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);       // ... Read More

How does selenium webdriver upload files to the browser?

Debomita Bhattacharjee
Updated on 28-Aug-2020 12:33:52
We can upload files to the browser with the help of Selenium webdriver. This is done with the help of sendKeys() method on the element which does the selection of the file by specifying the path of the file to be uploaded.While working on file upload functionality, we need to click on the Browse button. This is taken care of by webdriver for elements with attribute type having value as file. Also, the path of the file to be uploaded should be correct.ExampleCode Implementation.import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class FileUpld{    public static void ... Read More

How to Maximize window in chrome using webDriver (Python)?

Debomita Bhattacharjee
Updated on 28-Aug-2020 12:30:48
We can maximize windows on Chrome with a webdriver. While working on any automated test cases, if the browser opens in maximized mode then the probability of the scripts getting failed lessens.This is because if the element is visible, then the chances of its interaction increases. Also, if the window is maximized, then the testers or developers working on them gets a better visibility of the test steps.Some of the applications open in maximized mode automatically. Applying maximizing techniques on them does not have any impact on them. Let us see the methods with which we can maximize window in ... Read More

How to select checkboxes using selenium java webdriver?

Debomita Bhattacharjee
Updated on 28-Aug-2020 12:29:06
We can select the checkbox with Selenium. In an html document, each checkbox has an attribute type set to a value as checkbox. In order to select a checkbox, we shall first identify a checkbox with any locator and then apply the click() method to it.ExampleCode Implementation.import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class CheckBoxSelect{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String url ="https://www.tutorialspoint.com/selenium/selenium_automation_practice.htm";       driver.get(url);       driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);       // identify element ... Read More

How to switch to new window in Selenium for Python?

Debomita Bhattacharjee
Updated on 28-Aug-2020 12:26:55
Selenium can switch to new windows when there are multiple windows opened. There may be scenarios when filling a date field in a form opens to a new window or clicking a link, button or an advertisement opens a new tab.Selenium uses the current_window_handle and window_handles methods to work with new windows. The window_handles method contains all the window handle ids of the opened windows. The window id handles are held in the form of Set data structure [containing data type as String].The current_window_handle method is used to store the window handle id of the present active window. Finally to ... Read More

How to create right click using selenium?

Debomita Bhattacharjee
Updated on 28-Aug-2020 12:24:56
The right click is performed on any element on the web page to display its context menu. For example, if we right click on an edit box, a new menu with multiple options gets displayed.Selenium uses the Actions class to perform the right click action. The contextClick() is a method under Actions class to do the right click and once the menu opens, we can select an option from them via automation.First we need to move the mouse to the middle of the element with moveToElement() method, then do the right click. Next with build() method we shall carry out ... Read More

How to get screenshot of full webpage using Selenium and Java?

Debomita Bhattacharjee
Updated on 28-Aug-2020 12:22:43
Whenever we encounter a failure during testing, it is a common nature to capture the screenshots wherever there is a deviation from the expected result. Thus it is considered a mandatory step to attach a screenshot for creating a bug.While automating a bunch of test cases of a considerable number, capturing screenshot is critical to infer why a test case has failed for both the development and testing team. As they debug the failures, going through the screenshot and conclude if the failure is due to script issue or defect in the application.Sometimes we may need to capture the screenshots ... Read More

Fetch all href link using selenium in python.

Debomita Bhattacharjee
Updated on 28-Aug-2020 12:20:29
We can fetch href links in a page in Selenium by using the method find_elements(). All the links in the webpage are designed in a html document such that they are enclosed within the anchor tag.To fetch all the elements having tagname, we shall use the method find_elements_by_tag_name(). It will fetch a list of elements of anchor tag name as given in the method argument. If there is no matching tagname in the page, an empty list shall be returned.ExampleCode Implementation.from selenium import webdriver driver = webdriver.Chrome (executable_path="C:\chromedriver.exe") driver.maximize_window() driver.get("https://www.google.com/") # identify elements with tagname lnks=driver.find_elements_by_tag_name("a") # traverse ... Read More

Selenium Webdriver submit() vs click().

Debomita Bhattacharjee
Updated on 28-Aug-2020 06:36:08
The click() and submit() functions are quite similar in terms of functionalities. However there are minor differences. Let us discuss some differences between them.The submit() function is applicable only for and makes handling of form easier. It can be used with any element inside a form. The click() is only applicable to buttons with type submit in a form.The submit() function shall wait for the page to load however the click() waits only if any explicit wait condition is provided. If a form has a submit of type button, the submit() method cannot be used. Also, if a button ... Read More
Advertisements