If you have experience of around 2 years in automation testing then is one of the most common question you may be asked in interview
Here's the answer :
Here's the answer :
get() | navigate() |
---|---|
Waits till complete page loads. | Will not wait until the page loads, you can feel this experience only if page takes time to load, like more number of images or ajax calls etc...... |
We can not perform forward, backward & refresh operation in the browser. | We can perform forward, backward & refresh operation in the browser |
Absolute xpath: /html/body/div[2]/div/div/footer/section[3]/div/ul/li[3]/a |
Relative xpath: //body//section[3]/div/ul/li[3]/a |
driver.get("https://google.com"); driver.navigate().refresh();
driver.get("https://google.com"); driver.navigate().to(driver.getCurrentUrl());
driver.get("https://google.com"); driver.get(driver.getCurrentUrl());
driver.get("https://google.com"); driver.findElement(WebElement element).sendKeys("\uE035");
\uE035 is the ASCII code of F5 key. |
driver.get("https://google.com"); driver.findElement(By.id("firstname-placeholder")).sendKeys(Keys.F5);
1
| import org.openqa.selenium.support.ui.Select; |
1
| Select dropdown = new Select(driver.findElement(By.id("identifier"))); |
<select id="mySelect"> <option value="option1">Apple</option> <option value="option2">Mango</option> <option value="option3">Orange</option> </select>
1
2
| WebElement mySelectElement = driver.findElement(By.id("mySelect")); Select dropdown= new Select(mySelectElement); |
1
| Select dropdown = new Select(driver.findElement(By.id("mySelect"))); |
1
| dropdown.selectByVisibleText("Apple"); |
1
| dropdown.selectByIndex(2); |
1
| dropdown.selectByValue("option2"); |
1
| dropdown.deselectAll(); |
1
| dropdown.deselectByVisibleText("Apple"); |
1
| dropdown.deselectByIndex(2); |
1
| dropdown.deselectByValue("option2"); |
1
2
3
4
5
6
| WebElement mySelectElement = driver.findElement(By.id("mySelect")); Select dropdown= new Select(mySelectElement); dropdown.selectByVisibleText("Apple"); WebElement option = dropdown.getFirstSelectedOption(); System.out.println(option.getText()); //output "Apple" |
1
2
3
4
5
6
| WebElement mySelectElement = driver.findElement(By.id("mySelect")); Select dropdown= new Select(mySelectElement); List options = dropdown.getOptions(); for (WebElement option : options) { System.out.println(option.getText()); //output "option1", "option2", "option3" } |