Found 190 Articles for Selenium Web Driver

Typing Enter/Return key in Selenium.

Debomita Bhattacharjee
Updated on 31-Oct-2023 03:01:12

23K+ Views

We can type Enter/Return key in Selenium. We shall use the sendKeys method and pass Keys. ENTER as an argument to the method. Also, we can use pass Keys. RETURN as an argument to the sendKeys method for the same purpose.To use the Keys class, we have to incorporate import org.openqa.selenium.Keys to the code. Let us type Enter/Return after inputting text within the below edit box.Exampleimport org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.By; import org.openqa.selenium.Keys; public class TypeEnter{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver",       "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ... Read More

Wait for complex page with JavaScript to load using Selenium.

Debomita Bhattacharjee
Updated on 30-Nov-2020 10:34:40

3K+ Views

We can wait for a complex page with JavaScript to load with Selenium. After the page is loaded, we can invoke the Javascript method document.readyState and wait till complete is returned.SyntaxJavascriptExecutor js = (JavascriptExecutor)driver; js.executeScript("return document.readyState").toString().equals("complete");Next, we can verify if the page is ready for any action, by using the explicit wait concept in synchronization. We can wait for the expected condition presenceOfElementLocated for the element. We shall implement the entire verification within the try catch block.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import org.openqa.selenium.JavascriptExecutor; public class PageLoadWt{    public static void main(String[] args) { ... Read More

How to install Selenium WebDriver on Mac OS?

Debomita Bhattacharjee
Updated on 30-Nov-2020 10:32:25

3K+ Views

We can install Selenium on Mac OS. We shall take the help of Homebrew package manager for installation in Mac OS. Let us follow the step by step process −Install Selenium by running the command −pip install seleniumInstall the Chrome driver with the homebrew by running the command −brew cask install chromedriverVerify the version of the Chrome driver, by running the command −chromedriver −−versionCreate a test script and try to execute after save.from selenium import webdriver # driver initialization driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") # launch URL driver.get("https://www.tutorialspoint.com/index.htm")If the below error is triggered −unknown error: cannot find chrome binaryIt means the version ... Read More

Capturing JavaScript error in Selenium.

Debomita Bhattacharjee
Updated on 30-Nov-2020 10:29:16

1K+ Views

We can capture Javascript error in Selenium. This type of error appears at the Console Tab on opening the Developer tools in the browser. This can occur due to some functional issue in the page or due to extra logs which may cause performance issues.We can handle the Javascript errors with the driver object and manage method.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.List; import java.util.ArrayList; import org.openqa.selenium.logging.LogEntries; import org.openqa.selenium.logging.LogEntry; import org.openqa.selenium.logging.LogType; import java.util.logging.Level; import java.util.Set; public class JavascrptLogErs{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver",       "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver ... Read More

Switch tabs using Selenium WebDriver with Java.

Debomita Bhattacharjee
Updated on 30-Nov-2020 10:27:09

13K+ Views

We can switch tabs using Selenium. First we have to open a link in a new tab. The Keys.chord method along with sendKeys is to be used. The Keys.chord method allows you to pass more than one key at once. The group of keys or strings are passed as arguments to the method.We shall pass Keys.CONTROL and Keys.ENTER as arguments to the Keys.chord method. The whole string is then passed as an argument to the sendKeys method. Finally, the sendKeys method has to be applied on the link which is identified by driver.findElement method.SyntaxString clickl = Keys.chord(Keys.CONTROL, Keys.ENTER); driver.findElement(By.xpath("//*[text()='Terms of ... Read More

Capturing browser logs with Selenium WebDriver using Java.

Debomita Bhattacharjee
Updated on 30-Nov-2020 10:25:01

931 Views

We can capture browser logs with Selenium. We have to type cast the RemoteWebDriver to driver and then initialize it. Next, we have to use the setLogLevel method. The import org.openqa.selenium.remote.RemoteWebDriver statement needs to be added in code for the RemoteWebDriver.Syntax((RemoteWebDriver) driver).setLogLevel(Level.INFO);Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.remote.RemoteWebDriver import java.util.logging.Level; public class BrwLogs{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver",       "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       // Enable logging with setLogLevel method       ((RemoteWebDriver) driver).setLogLevel(Level.INFO);       driver.get("https://www.tutorialspoint.com/index.htm");       ... Read More

How to handle authentication popup with Selenium WebDriver using Java?

Debomita Bhattacharjee
Updated on 30-Nov-2020 10:23:19

3K+ Views

We can handle authentication popup with Selenium. To do this, we have to pass the user credentials within the URL. We shall have to add the username and password to the URL.Syntaxhttps://username:password@URL https://admin:admin@the−nternet.herokuapp.com/basic_auth Here, the admin is the username and password. URL − www.the-internet.herokuapp.com/basic_authLet us work and accept the below authentication popup.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; public class AuthnPopup{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver",       "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String u = "admin";       // adding username, password with ... Read More

Why do we use WebDriver instead of Selenium IDE?

Debomita Bhattacharjee
Updated on 30-Nov-2020 10:21:11

352 Views

We can use webdriver instead of Selenium IDE. The Selenium IDE is a record and playback tool but not dependable. The web elements which are dynamic cannot be handled well with Selenium IDE.Selenium IDE can be used for an easy solution to automation, but for a full regression suite, Selenium webdriver should be used. Some of the differences between Selenium IDE and Selenium webdriver are −Sl. No.Selenium IDESelenium Webdriver1.It supports only Firefox.It supports all the major browsers.2.Simply a record and playback tool.Not a record and playback tool.3.Architecture based on Javascript.Architecture not based on Javascript. Communicates with browser applications.4.Does not support ... Read More

Can I set any of the attribute value of a WebElement in Selenium?

Debomita Bhattacharjee
Updated on 30-Nov-2020 10:20:07

5K+ Views

We can set any attribute value of a webelement in Selenium. Selenium can run Javascript commands by the executeScript method. The command to be executed is passed as an argument to the method.Next, we have to identify the element with the help of the Javascript method document.getElementsByClassname. It returns a list of elements, to point to the first element we shall add index [0]. To set the attribute we shall use the setAttribute method.Syntax for setting the style attribute −JavascriptExecutor j = (JavascriptExecutor) driver; js.executeScript ("document.getElementsByClassName('heading')[0].setAttribute('style', 'background-color: red')");Let us set the background color of webelement to red.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; ... Read More

How to wait for options in a select to be populated in Selenium?

Debomita Bhattacharjee
Updated on 30-Nov-2020 10:17:16

2K+ Views

We can wait for options in a select tag to be populated with Selenium. This can be done with the explicit wait concept in synchronization. The explicit wait is designed on the expected condition for an element.To wait for the options, we shall verify if presenceOfNestedElementsLocatedBy is available within the explicit wait time. We shall implement the entire verification within the try catch block.Let us see if the options are available for selection in the Continents dropdown. The ExpectedCondition along with WebDriverWait is used for explicit wait.HTML code of the select dropdown.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import ... Read More

Advertisements