Hi,
I am automating a flow where for few of the elements I don’t have an id/name attribute to the tag so I have used XPATH. These XPATHs are working fine in Chrome/Firefox & IE but failing in Edge browser.
While debugging I found that Edge is giving InvalidSelectorException only for XPATHs.
Here is the sample code I am running.
package research;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class Edge {
private WebDriver driver;
JavascriptExecutor js;
@BeforeTest
public void setUp() {
System.setProperty("webdriver.edge.driver", System.getProperty("user.dir") + "/Drivers/MicrosoftWebDriver.exe");
driver = new EdgeDriver();
js = (JavascriptExecutor) driver;
}
@AfterTest
public void tearDown() {
driver.quit();
}
@Test
public void untitled() throws InterruptedException {
driver.get("http://testproject.com/test");
driver.manage().window().maximize();
driver.findElement(By.id("User")).sendKeys("Test");
driver.findElement(By.id("Password")).sendKeys("Test");
driver.findElement(By.id("Password")).sendKeys(Keys.ENTER);
{
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("dropdown")));
}
driver.findElement(By.id("dropdown")).click();
{
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("searchInput")));
}
driver.findElement(By.id("searchInput")).sendKeys("Test");
driver.findElement(By.id("searchInput")).sendKeys(Keys.ENTER);
Thread.sleep(3000);
driver.switchTo().frame(11);
driver.findElement(By.xpath("//div[@id=\"ADiv_22\"]")).click();
driver.findElement(By.xpath("//nobr[contains(.,\'User\')]")).click();
{
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("searchUserInput")));
}
driver.findElement(By.xpath("//input[@id=\'searchUserInput\']")).sendKeys("TestUser");
driver.findElement(By.xpath("//input[@id=\'searchUserInput\']")).sendKeys(Keys.ENTER);
driver.findElement(By.xpath("//input[@id=\'searchUserInput\']")).sendKeys(Keys.ENTER);
{
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//img[@id=\'Active\']")));
}
driver.findElement(By.xpath("//img[@id=\'Active\']")).click();
driver.findElement(By.xpath("//img[@id=\'InActive\']")).click();
driver.findElement(By.id("Close")).click();
driver.findElement(By.id("Close")).click();
driver.switchTo().defaultContent();
driver.findElement(By.id("userDiv")).click();
driver.findElement(By.id("signOut")).click();
}
}
Is there something I am missing here?
I am running my tests on Microsoft Edge 44.17763.831.0 and have downloaded driver exe by running this command- DISM.exe /Online /Add-Capability /CapabilityName:Microsoft.WebDriver~~~~0.0.1.0
Thanks,
Chandresh Parmar