
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 517 Articles for Selenium

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

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

580 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

593 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

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

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

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

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

5K+ Views
We can wait until the page is completely loaded in Selenium webdriver by using the JavaScript Executor. Selenium can run JavaScript commands with the help of the executeScript method.We have to pass return document.readyState as a parameter to the executeScript method and then verify if the value returned by this command is complete.SyntaxJavascriptExecutor j = (JavascriptExecutor)driver; if (j.executeScript("return document.readyState").toString().equals("complete")){ System.out.println("Page has loaded"); }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; public class PageLdWait{ public static void main(String[] args) { System.setProperty("webdriver.gecko.driver", "C:\Users\ghs6kor\Desktop\Java\geckodriver.exe"); ... Read More

4K+ Views
We can handle alerts in Selenium webdriver by using the Alert interface. An alert can be of three types – a prompt which allows the user to input text, a normal alert and a confirmation alert.By default, the webdriver can only access the main page, once an alert comes up, the method switchTo().alert() is used to shift the focus webdriver control to the alert.A normal alert is shown below −A confirmation alert is shown below −A prompt alert is shown below −To accept an alert (to click on the OK button in alert), the method switchTo().alert().accept() is used. To dismiss ... Read More