Found 871 Articles for Automation Testing

How can I perform mouse hover action in Selenium-Python?

Debomita Bhattacharjee
Updated on 06-Apr-2021 11:46:17

16K+ Views

We can perform mouseover action in Selenium webdriver in Python by using the ActionChains class. We have to create an object of this class and then apply suitable methods on it.In order to move the mouse to an element, we shall use the move_to_element method and pass the element locator as a parameter. Then apply the perform method to actually perform this action. After hovering on the element, we can apply click action on it with the help of the click method.Syntaxa = ActionChains(driver) m= driver.find_element_by_link_text("Enabled") a.move_to_element(m).perform()Let us try to hover on the element Enabled as shown on the below ... Read More

Need Selenium to wait until the document is ready

Debomita Bhattacharjee
Updated on 06-Apr-2021 11:44:07

4K+ Views

We can wait until the document is ready (page loaded completely) in Selenium by applying the method pageLoadTimeout. The wait time is passed as a parameter to this method.The webdriver waits for this duration for the page to load completely. If this time gets elapsed without page loading, a TimeoutException is thrown.Syntaxdriver.manage().timeouts().pageLoadTimeout(3, TimeUnit.SECONDS);ExampleCode Implementation with pageLoadTimeoutimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; public class PageLdTime{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       //page load ... Read More

Scroll element to the middle of the screen with Selenium

Debomita Bhattacharjee
Updated on 06-Apr-2021 11:42:35

4K+ Views

We can scroll to the middle of the screen with Selenium webdriver using the JavaScript Executor. Selenium can execute JavaScript commands with the help of the executeScript method.To scroll to the middle of the screen, we have to first identify the element upto which we want to scroll on the page. Then pass scrollIntoView and the web element as parameters to the executeScript method.JavaScript command scrollIntoView can have multiple optional parameters. They are −behavior – This can have the values - smooth or auto. It describes the animation of the transition. The default value is auto.block – This can have ... Read More

How can I download Microsoft WebDriver/Edge Driver to use with Selenium?

Debomita Bhattacharjee
Updated on 06-Apr-2021 11:29:20

3K+ Views

We can download Microsoft/Edge Driver to use with Selenium. The Microsoft Edge driver allows communication of the tests developed in Selenium with the Edge browser.To download the msedgedriver.exe file, we have to first navigate to the following link − https://developer.microsoft.com/en-us/microsoftedge/tools/webdriver/#downloadsThen move to the Downloads section, and click on the link based on the local operating system and browser version we have.Once the download is completed, a zip file gets saved. It needs to be extracted and stored in a location. After extracting it, the executable file - msedgedriver.exe file is to be kept at a desired location.We have to configure ... Read More

What is the best way to handle a Javascript popup using Selenium Webdriver?

Debomita Bhattacharjee
Updated on 06-Apr-2021 11:28:04

432 Views

We can handle a JavaScript pop-up using Selenium webdriver with the help of the Alert interface. The alerts are pop-ups that shift the focus from the main webpage to the alert text appearing on the page.By default, the webdriver has focus on the main page, to access the alert we have to explicitly switch the driver focus from the main page to the alert box. The alerts can be of two types – web based and window based. JavaScript pop-ups are the web based alerts.The switchTo().alert() method is used to switch the driver focus to the alert. Once the driver ... Read More

How to avoid “StaleElementReferenceException” in Selenium?

Debomita Bhattacharjee
Updated on 06-Apr-2021 11:27:24

486 Views

The StaleElementReferenceException is thrown if the webdriver makes an attempt to access a web element which is currently not available or invalid in DOM.This can be due to refresh of the page or an element is accidentally deleted or modified or no longer connected to DOM. This type of exception can be avoided by following the below techniques −Page refresh.Having a retry mechanism.Having a try-catch block.Waiting for some expected criteria like presenceOfElementLocated or refreshing a page on getting a stale condition for an element.ExampleCode Implementation having StaleElementExceptionimport 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 StaleElemntExc{   ... Read More

sendKeys() not working in Selenium Webdriver

Debomita Bhattacharjee
Updated on 06-Apr-2021 11:26:50

5K+ Views

If we encounter issues while working with the sendKeys method, then we can use the JavaScript Executor to input text within an edit box. Selenium can run JavaScript commands with the help of the executeScript method.JavaScript command to be used is passed as a parameter to this method. To input text we shall first identify the edit field with the JavaScript method document.getElementsByClassName. Then apply the value method on it.Let us try to enter text tutorialspoint to the below Google search box −SyntaxJavascriptExecutor j = (JavascriptExecutor) driver; j.executeScript("document.getElementsByName('qwe')[0].value= 'tutorialspoint'");Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.JavascriptExecutor; ... Read More

How to submit a form in Selenium webdriver if submit button can't be identified?

Debomita Bhattacharjee
Updated on 06-Apr-2021 11:25:44

2K+ Views

We can submit a form in Selenium webdriver even if the submit button cannot be identified. This can be achieved by locating any element within the form tag and the applying submit method on it. A form in the html code is identified by the tag.Let us investigate the html code of element with in a form tag −In the above example, we shall try to submit the form with the help of the Email or Password field and not by clicking on the Sign in button.Syntaxdriver.findElement(By.className("input__input")).sendKeys("96968547"); driver.findElement(By.className("session_password")).sendKeys("test123"); driver.findElement(By.className("session_password")).submit();Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import java.util.concurrent.TimeUnit; public ... Read More

How to Scroll Down or UP a Page in Selenium Webdriver?

Debomita Bhattacharjee
Updated on 06-Apr-2021 11:25:17

9K+ Views

We can scroll down or up a page in Selenium webdriver using JavaScript Executor. Selenium can execute JavaScript commands with the help of the executeScript method.To scroll down vertically in a page we have to use the JavaScript command window.scrollBy. Then pass the pixel values to be traversed along the x and y axis for horizontal and vertical scroll respectively.The positive value set for x-axis shall scroll the page to the right while the negative value for x-axis shall scroll it to the left. Similarly, the positive value set for y-axis shall scroll down the page while the negative value ... Read More

How to click on sign up button using Java in Selenium I am able to open page but not able to click?

Debomita Bhattacharjee
Updated on 06-Apr-2021 11:24:14

4K+ Views

We can click on the Sign up button using Java in Selenium. First of all, we have to identify the Sign up button with the help of any of the locators like id, class name, name, link text, xpath, css or partial link text. After identification, we have to click on the Sign up the button with the help of the method click.SyntaxWebElement m=driver. findElement(By.id("loc-txt")); m.click();ExampleCode Implementation with clickimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import java.util.concurrent.TimeUnit; public class SignIn{    public static void main(String[] args) {       System.setProperty("webdriver.gecko.driver", ... Read More

Advertisements