Microsoft WebDriver - XPATH locators are not working.

63 views
Skip to first unread message

Chandresh Parmar

unread,
Dec 31, 2019, 6:31:36 AM12/31/19
to Selenium Users

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();

 
}

}


Error Details - 
org.openqa.selenium.InvalidSelectorException: The specified selector is invalid.
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/invalid_selector_exception.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'CNPARMAR', ip: '11.161.93.3', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_231'
Driver info: org.openqa.selenium.edge.EdgeDriver
Capabilities {acceptInsecureCerts: false, browserName: MicrosoftEdge, browserVersion: 44.17763.831.0, javascriptEnabled: true, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}}
Session ID: 7615C7B1-CAFA-4830-9321-62BA58CDF585
*** Element info: {Using=xpath, value=//div[@id="ADiv_22"]}


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


Reply all
Reply to author
Forward
0 new messages