Found 871 Articles for Automation Testing

How to switch to new window in Selenium for Python?

Debomita Bhattacharjee
Updated on 28-Aug-2020 12:26:55

1K+ Views

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

2K+ Views

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

641 Views

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

19K+ Views

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

10K+ Views

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

Fill username and password using selenium in python.

Debomita Bhattacharjee
Updated on 28-Aug-2020 06:32:40

2K+ Views

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

4K+ Views

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

449 Views

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

539 Views

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

3K+ Views

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

Advertisements