Microsoft Edge Webdriver sometimes gives the below error when you click on web element in your test code:
This is a known issue and can be traced at:
https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/5238133/
There's a workaround available till Microsoft Edge team resolves this issue. You can click on the element using javascript in your test. It's an easy to understand three lines of code.
WebElement e = driver.findElement(By.linkText("Check Out"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", e);
Below is an example of a method that uses JavaScript to click on elements:
One important point to take into account is you will have to use explicit or fluent wait statements frequently to give JavaScriptExecuter the time to click on the web element.
This is a known issue and can be traced at:
https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/5238133/
There's a workaround available till Microsoft Edge team resolves this issue. You can click on the element using javascript in your test. It's an easy to understand three lines of code.
WebElement e = driver.findElement(By.linkText("Check Out"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", e);
- Start with finding the element and storing it in a WebElement object.
- Create JavaScriptExecuter interface reference variable by typecasting the web driver object.
- Call the executeScript method and pass it the script to be executed and web element object from step 1.
Below is an example of a method that uses JavaScript to click on elements:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test (groups = {"Check Out Cancel"}) | |
public void Cancel() | |
{ | |
//Click on Check Out using JavaScript | |
WebElement e= driver.findElement(By.linkText("Check Out")); | |
JavascriptExecutor executor = (JavascriptExecutor)driver; | |
executor.executeScript("arguments[0].click();", e); | |
// Find Elements and populate dummy data | |
driver.findElement(By.id("email")).sendKeys("test@testmail.com"); | |
driver.findElement(By.id("name")).sendKeys("Pete"); | |
driver.findElement(By.id("address")).sendKeys("test street, test=123, ca, usa"); | |
Select cardType = new Select(driver.findElement(By.id("card_type"))); | |
cardType.selectByVisibleText("Visa"); | |
driver.findElement(By.id("card_number")).sendKeys("12345453434745"); | |
driver.findElement(By.id("cardholder_name")).sendKeys("Pete my Fish"); | |
driver.findElement(By.id("verification_code")).sendKeys("007"); | |
driver.findElement(By.id("address")).sendKeys("test street, test=123, ca, usa"); | |
//Click on Cancel using JavaScript | |
WebElement e1= driver.findElement(By.linkText("Cancel")); | |
JavascriptExecutor executor1 = (JavascriptExecutor)driver; | |
executor1.executeScript("arguments[0].click();", e1); | |
//Explicitly Wait for javascript to perform click | |
WebDriverWait wait = new WebDriverWait(driver,10); | |
wait.until(ExpectedConditions.titleIs("Menu")); | |
String Tittle=driver.getTitle(); | |
Assert.assertEquals(Tittle,"Menu"); | |
} |
No comments:
Post a Comment