xpath query throws InvocationTargetException
See original GitHub issueThe problem
When using appium driver to search for element by xpath, most of the search queries work, but some don’t. Instead the query with method findElement( By.xpath() ) or findElementByXPath() throws InvocationTargetException. I’m using the native android browser app. Might be that this is a bug or you could tell me what’s going wrong. THx
Environment
- Appium version (or git revision) that exhibits the issue: 1.6.5
- Last Appium version that did not exhibit the issue (if applicable): -
- Desktop OS/version used to run Appium: Windows 7
- Node.js version (unless using Appium.app|exe): -
- Mobile platform/version under test: Android 6.0
- Real device or emulator/simulator: simulator
- Appium CLI or Appium.app|exe: 1.2.1
Details
The xpath which I’m search for is: “//*[@id=“edge-page”]/div[3]/div/div/div/div[2]/div[@class=“sport”]/a/p/span[text()=“Bundesliga”]”. Searching for this xpath in Chrome returns a valid element, but when using this xpath in my test, it throws the mentioned exception.
public void selectLeague( String league ) { WebElement clickableLeague = driver.findElementByXPath("//*[@id=\"edge-page\"]/div[3]/div/div/div/div[2]/div[@class=\"sport\"]/a/p/span[text()=\"Bundesliga\"]" ); if ( clickableLeague != null ) { clickableLeague.click(); } }
Detailed information about the exception:
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {“method”:“xpath”,“selector”:"//[@id=“edge-page”]/div[3]/div/div/div/div[2]/div[@class=“sport”]/a/p/span[text()=“Bundesliga”]"} (Session info: chrome=44.0.2403.119) (Driver info: chromedriver=2.19.346078 (6f1f0cde889532d48ce8242342d0b84f94b114a1),platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: ‘3.5.3’, revision: ‘a88d25fe6b’, time: ‘2017-08-29T12:42:44.417Z’ System info: host: ‘ILOFAPPEXP4’, ip: ‘192.168.56.1’, os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.8.0_66’ Driver info: io.appium.java_client.AppiumDriver Capabilities [{deviceScreenSize=480x854, networkConnectionEnabled=true, recreateChromeDriverSessions=true, clearSystemFiles=true, noReset=true, warnings={}, databaseEnabled=false, deviceName=emulator-5554, avd=API_23, platform=LINUX, deviceUDID=emulator-5554, chromedriverExecutable=C:\Users\lo\chromedriver\chromedriver_v2_19.exe, desired={recreateChromeDriverSessions=true, chromedriverExecutable=C:\Users\lo\chromedriver\chromedriver_v2_19.exe, clearSystemFiles=true, noReset=true, newCommandTimeout=720, browserName=Browser, platformName=Android, deviceName=API_23, avd=API_23}, newCommandTimeout=720, platformVersion=6.0, webStorageEnabled=false, locationContextEnabled=false, takesScreenshot=true, browserName=Browser, javascriptEnabled=true, deviceModel=Android SDK built for x86, deviceManufacturer=unknown, platformName=LINUX}] Session ID: e4452718-e4bb-42c3-8406-b13651494a54 *** Element info: {Using=xpath, value=//[@id=“edge-page”]/div[3]/div/div/div/div[2]/div[@class=“sport”]/a/p/span[text()=“Bundesliga”]} at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:422) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:215) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167) at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40) at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:82) at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:45) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164) at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:89) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:646) at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42) at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:416) at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:62) at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1) at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:518) at io.appium.java_client.DefaultGenericMobileDriver.findElementByXPath(DefaultGenericMobileDriver.java:140) at io.appium.java_client.AppiumDriver.findElementByXPath(AppiumDriver.java:1) at com.intralot.stepDefinition.selectLeague(stepDefinition.java:254) at ?.And user selects “Bundesliga”(stepDefinition.feature:11)
Link to Appium logs
Issue Analytics
- State:
- Created 6 years ago
- Comments:9
Top GitHub Comments
Ok, I found a solution: Instead of using xpath: //*[@id="edge-page"]/div[3]/div/div/div/div[2]/div[@class="sport"]/a/p/span[text()="Bundesliga"] im using now: //div[@id=“edge-page”]/descendant::div/div[@class=“sport”]/a/p/span[text()=“Bundesliga”]/…/…
https://developers.google.com/web/tools/chrome-devtools/remote-debugging/