Found 190 Articles for Selenium Web Driver

What are the different types of wait available in Selenium?

Debomita Bhattacharjee
Updated on 10-Jun-2020 13:51:04

598 Views

The different types wait available in Selenium are listed below −Implicit waitThis is one of dynamic waits in Selenium with the Syntax as −driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);Explicit waitThis is one of dynamic waits in Selenium with the Syntax as −WebDriverWait w = new WebDriverWait(driver, ); w.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("")));Fluent waitThis is one of dynamic waits in Selenium with the Syntax as −Wait w = new FluentWait(driver).withTimeout(Duration.ofSeconds(30)) .pollingEvery(Duration.ofSeconds(3)).ignoring(NoSuchElementException.class);Static waitThis is used to pause the execution for a specified amount of time.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.Keys; 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 ThreadWait {    public static void main(String[] args) throws InterruptedException ... Read More

How to set the size of the browser window in Selenium?

Debomita Bhattacharjee
Updated on 10-Jun-2020 13:46:08

3K+ Views

We can set the size of the browser window by the following methods −getSize() methodJavascript executorExampleWith setSize() method.import org.openqa.selenium.By; import org.openqa.selenium.Keys; 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 BrowserDimension {    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String url = "https://www.tutorialspoint.com/index.htm";       driver.get(url);       // maximize the browser       driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);       // fetching the current window size with getSize()       System.out.println(driver.manage().window().getSize());       //Create object of Dimensions ... Read More

How to perform scrolling action on page in Selenium?

Debomita Bhattacharjee
Updated on 10-Jun-2020 13:44:08

937 Views

We can perform the following actions with respect to scrolling in Selenium −Vertical scrollingThe scrolling down to a specific pixel.JavascriptExecutor j = (JavascriptExecutor) driver; // scroll down by 1500 pixel with coordinates 0 and 1500 in x, y axes j.executeScript("window.scrollBy(0, 1500)");The scrolling down to the bottom of the page.JavascriptExecutor j = (JavascriptExecutor) driver; // scroll down the bottom of page js.executeScript("window.scrollTo(0, document.body.scrollHeight)");ExampleFor vertical scroll down till the element is visible.import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.JavascriptExecutor; public class ScrollDownVisible {    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");   ... Read More

How to extract the attribute value of an element in Selenium?

Debomita Bhattacharjee
Updated on 10-Jun-2020 13:35:43

877 Views

We can extract the attribute value of an element in Selenium with the help of getAttribute() method. Once we locate the element, this method is used to get the attribute value of the element and assigned to a variable.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.Keys; 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 AttributeType {    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String url = "https://www.tutorialspoint.com/index.htm";       driver.get(url);       driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);       //Using id tagname attribute combination ... Read More

How to press ENTER inside an edit box in Selenium?

Debomita Bhattacharjee
Updated on 10-Jun-2020 13:34:13

623 Views

Selenium gives Enum Key macros to perform the enter action.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.Keys; 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 PressEnter {    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String url = " https://www.tutorialspoint.com/index.htm";       driver.get(url);       driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);       // Keys.ENTER passed through sendKeys() method       driver.findElement(By.className("gsc-input")).sendKeys("Keys.ENTER");       driver.close();    } }Read More

How to perform browser navigations in Selenium?

Debomita Bhattacharjee
Updated on 10-Jun-2020 13:24:52

509 Views

There are various navigate() methods to perform navigations in Selenium. They are as the listed below −navigate().to(url)This is used to launch a new browser and open a particular URL as in the parameter.navigate().refresh()This is used to reload a page.navigate().back()This is used to jump to the previous page as per browser history context.navigate().forward()This is used to jump to the next page as per browser history context.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.Keys; 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 BrowserNavigation {    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = ... Read More

What is xpath in Selenium?

Debomita Bhattacharjee
Updated on 10-Jun-2020 13:13:52

3K+ Views

Xpath is one of the most important locators used in Selenium for identifying web elements. It works in the following ways −It navigates through the Document Object Model (DOM) with the help of elements and their attributes for identification.Although it helps to locate the elements uniquely, it is slower in terms of speed from the other locators.An xpath is represented by two ways namely ‘/ ‘and ‘// ‘. A forward single slash means absolute path. Here xpath traverses direct from parent to child in DOM. Thus in absolute xpath we have to travel from the root node to the target.Syntax ... Read More

How to identify the elements by partially comparing to its attributes in Selenium?

Debomita Bhattacharjee
Updated on 10-Jun-2020 12:57:32

1K+ Views

We can identify elements by partially comparing to its attributes in Selenium with the help of regular expression. In xpath, there is contains () method. It supports partial matching with the value of the attributes. This method comes as useful while dealing with elements having dynamic values in their attributes.Syntax driver.findElement(By.xpath("//tagname[contains(@attributes, ’value’)]"))In CSS, we can identify elements by partially comparing to its attributes by using regular expressions. There can be three scenarios −Using ^ to target attributes starting with a particular text.Syntax −driver.findElement(By.cssSelector("tagname[attribute^=’value’]"))Using $ to target attributes ending with a particular text.Syntax −driver.findElement(By.cssSelector("tagname[attribute$=’value’]"))Using * to target attributes containing a particular text.Syntax −driver.findElement(By.cssSelector("tagname[attribute*=’value’]"))Exampleimport org.openqa.selenium.By; ... Read More

How to identify elements based on text visible on page in Selenium?

Debomita Bhattacharjee
Updated on 10-Jun-2020 12:59:04

2K+ Views

To identify elements based on text visible on page, text() method is used in xpath.Syntax −driver.findElement(By.xpath("//tagname[text()=’value’]"))Exampleimport org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class TextMatch {    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String url = "https://www.tutorialspoint.com/index.htm";       driver.get(url);       driver.manage().window().maximize();       driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);       //xpath with text() method       driver.findElement(By.xpath("//*[text()=’GATE Exams’]")).click();       driver.close();    } }Read More

What are the various locators that Selenium supports?

Debomita Bhattacharjee
Updated on 10-Jun-2020 12:44:25

151 Views

The various types of locators that Selenium support are listed below −ID − This attribute is unique for every element.Syntax − driver.findElement(By.id("")).Name − This attribute is not unique for every element.Syntax − driver.findElement(By.name("")).CSS Selector − This can be derived from element tags and attributes.Syntax −driver.findElement(By.cssSelector("")).xpath − This can be derived from element tags and attributes.Syntax −driver.findElement(By.xpath("")).TagName − This can be derived from the HTML tags to identify the elements.Syntax − driver.findElement(By.tagName("")). LinkText − This can be derived from the anchor text to identify the elementszSyntax − driver.findElement(By.linkText("")).PartialLinkText − This can be derived from the partial anchor text to identify the elementsSyntax − driver.findElement(By.partialLinkText("")).Classname ... Read More

Advertisements