Found 466 Questions for Selenium

Fill username and password using selenium in python.

Debomita Bhattacharjee
Updated on 28-Aug-2020 06:32:40
We can fill username and password fields in a login page with Selenium. This is considered an authentication step for any application. Once the username and password is entered, we have to click the login button.ExampleCode Implementation.import time from selenium import webdriver driver = webdriver.Chrome (executable_path="C:\chromedriver.exe") driver.get("https://mail.rediff.com/cgi-bin/login.cgi") # identify username, password and signin elements driver.find_element_by_name("login").send_keys("tutorialspoint") time.sleep(0.2) driver.find_element_by_name("passwd").send_keys("pass123") time.sleep(0.4) driver.find_element_by_class_name("signinbtn").click() driver.closeIf a valid username and password is provided, we shall be directed to the home page of the application.OutputRead More

Test if element is present using Selenium WebDriver?

Debomita Bhattacharjee
Updated on 28-Aug-2020 06:31:00
We can verify if an element is present using Selenium. This can be determined with the help of findElements() method. It returns the list of elements matching the locator we passed as an argument to that method.In case there is no matching element, an empty list [having size = 0] will be returned. We are not using the findElement() method since if there is no matching element, this method gives NoSuchElementException.In an event of any exception, we have to handle it with a try catch block.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; import java.util.List; public class ... Read More

How to take partial screenshot (frame) with Selenium WebDriver?

Debomita Bhattacharjee
Updated on 28-Aug-2020 06:27:47
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 screenshot ... Read More

How to automate drag & drop functionality using Selenium WebDriver Java?

Debomita Bhattacharjee
Updated on 28-Aug-2020 06:25:06
The drag and drop action is done with the help of a mouse. It happens when we drag and then place an element from one place to another. This is a common scenario when we try to move a file from one folder to another by simply drag and drop action.Selenium uses the Actions class to perform the drag drop action. The dragAndDrop(source, destination) is a method under Actions class to do drag and drop operation. The method will first do a left click on the element, then continue the click to hold the source element. Next it shall move ... Read More

How can I scroll a web page using selenium webdriver in python?

Debomita Bhattacharjee
Updated on 16-Feb-2021 06:49:03
Sometimes we need to perform action on an element which is not present in the viewable area of the page. We need to scroll down to the page in order to reach that element.Selenium cannot perform scrolling action directly. This can be achieved with the help of Javascript Executor and Actions class in Selenium. DOM can work on all elements on the web page with the help of Javascript.Selenium can execute commands in Javascript with the help of the execute_script() method. For the Javascript solution, we have to pass true value to the method scrollIntoView() to identify the object below ... Read More

How to perform mouseover function in Selenium WebDriver using Java?

Debomita Bhattacharjee
Updated on 28-Aug-2020 06:20:57
A mouse hover is done on an element to fire an event on that element. If we hover on the menus of a webpage the submenus appears. Thus this event gets triggered on hovering on an element.It is evident from the above image that on hovering over the Packages menu the color of the text changed along with the tooltip display. Selenium has the Actions class that contains multiple APIs for mouse cursor movement.The moveToElement() method is used to perform mouse movement. We have to import org.openqa.selenium.interactions.Actions for Action class. Along with moveToElement() we have to use the perform() method ... Read More

How do I find an element that contains specific text in Selenium Webdriver?

Debomita Bhattacharjee
Updated on 28-Aug-2020 06:18:35
We can find an element with a specific text visible on the screen in Selenium. This is achieved with the xpath locator. The xpath locator contains some in-built functions that help to create customized xpath.Let us consider a portion of the web page as given below −text() − It is a built in function to identify an element based on the text displayed on the screen. For example, if we want to identify Library from the above webpage, the customized xpath with text() should be −Syntax//*[text()='Library']contains() − It is a built in function to identify an element based on the ... Read More

Scroll Element into View with Selenium.

Debomita Bhattacharjee
Updated on 28-Aug-2020 06:15:36
We may need to perform action on an element which is not present in the viewable area of the page. We need to scroll down to the page in order to reach that element.Selenium cannot perform scrolling action directly. This can be achieved with the help of Javascript Executor and Actions class in Selenium. DOM can work on all elements on the web page with the help of Javascript.Selenium can execute commands in Javascript with the help of the execute_script() method. For the Javascript solution, we have to pass true value to the method scrollIntoView() to identify the object below ... Read More

How to take screenshot with Selenium WebDriver?

Debomita Bhattacharjee
Updated on 28-Aug-2020 06:09:49
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.Let us discuss which part of the page ... Read More

Can selenium handle Windows based pop up?

Debomita Bhattacharjee
Updated on 28-Aug-2020 06:04:55
Selenium can handle Windows based pop up. There may be scenarios where a web page opens more than one window after performing some actions on it. The child windows that get opened may be a pop up containing some information or advertisement.Selenium uses the getWindowHandles () and getWindowHandle () methods to work with child windows. The getWindowHandles () 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 getWindowHandle () method is used to store the window handle id of the ... Read More
Advertisements