- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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 871 Articles for Automation Testing
643 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
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
986 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
934 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
675 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
535 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
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
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
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
160 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