2

I have never experienced an error like this before. Is the website I'm visiting resistant to the use of automation tests?

Code:

public class DirectoryAutomation {

    public static void main(String[] args) throws IOException, InterruptedException {

        System.setProperty("webdriver.chrome.driver", "C:\\Users\\MartinErlic\\eclipse-workspace\\DirectoryAutomation\\libs\\chromedriver.exe");
        ChromeDriver driver = new ChromeDriver();
        driver.get("https://www.arivify.com/property/az/mesa");
        Thread.sleep(2000);
        driver.findElement(By.xpath("xpath=//div[@id='__layout']/div/div[2]/section/div/table/tbody/tr/td")).click();
    }
}

Exception:

Starting ChromeDriver 78.0.3904.105 (60e2d8774a8151efa6a00b1f358371b1e0e07ee2-refs/branch-heads/3904@{#877}) on port 21763
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[1579544613.399][WARNING]: This version of ChromeDriver has not been tested with Chrome version 79.
[1579544615.411][WARNING]: Timed out connecting to Chrome, retrying...
Jan. 20, 2020 10:23:37 A.M. org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Exception in thread "main" org.openqa.selenium.InvalidArgumentException: invalid argument
  (Session info: chrome=79.0.3945.130)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'DESKTOP-AS2OG7F', ip: '217.157.87.231', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '13.0.1'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 79.0.3945.130, chrome: {chromedriverVersion: 78.0.3904.105 (60e2d8774a81..., userDataDir: C:\Users\MARTIN~1\AppData\L...}, goog:chromeOptions: {debuggerAddress: localhost:60322}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 613ee3b0588734b777f2ceb5d7715c9c
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:277)
    at DirectoryAutomation.main(DirectoryAutomation.java:42)

Updated Exception:

Starting ChromeDriver 79.0.3945.36 (3582db32b33893869b8c1339e8f4d9ed1816f143-refs/branch-heads/3945@{#614}) on port 24206
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[1579548408.283][WARNING]: Timed out connecting to Chrome, retrying...
Jan. 20, 2020 11:26:50 A.M. org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Exception in thread "main" org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression xpath=//a[contains(@href,'/property/search/hEC4ocSW0')] because of the following error:
TypeError: Failed to execute 'evaluate' on 'Document': The result is not a node set, and therefore cannot be converted to the desired type.
  (Session info: chrome=79.0.3945.130)
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:17:03'
System info: host: 'DESKTOP-AS2OG7F', ip: '192.168.1.75', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '13.0.1'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 79.0.3945.130, chrome: {chromedriverVersion: 79.0.3945.36 (3582db32b3389..., userDataDir: C:\Users\MARTIN~1\AppData\L...}, goog:chromeOptions: {debuggerAddress: localhost:51045}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: c52709d658575c36b6705f1db4ce20b2
*** Element info: {Using=xpath, value=xpath=//a[contains(@href,'/property/search/hEC4ocSW0')]}
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:323)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:428)
    at org.openqa.selenium.By$ByXPath.findElement(By.java:353)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:315)
    at DirectoryAutomation.main(DirectoryAutomation.java:42)
DebanjanB
  • 118,661
  • 30
  • 168
  • 217
Martin Erlic
  • 4,691
  • 10
  • 63
  • 123
  • 1
    Could you please share a minimal example of your code that produces this exception? – Julian Jan 20 '20 at 18:38
  • @Julian I updated my post with the exact code that I'm using. – Martin Erlic Jan 20 '20 at 18:48
  • just a note that thread.sleep is not necessary there. Selenium will wait for pageready state... you seem to have an invalid selector. The exception you posted includes "xpath=" which should not be a part of the selector. – pcalkins Jan 20 '20 at 20:20
  • Thanks! This is it. I was lazily copy/pasting from the Selenium IDE, which unnecessarily appends css to the selector: ``css=tr:nth-child(2) a``. It should have just been ``tr:nth-child(2) a``. Same goes for xpath. Need to remove ``xpath=``. Much needed sanity check! Thanks. – Martin Erlic Jan 20 '20 at 20:32

2 Answers2

2

Does this occur if you try other websites using this same code (Specifically using the same webdriver version and chrome version)?

Seeing this [1579544613.399][WARNING]: This version of ChromeDriver has not been tested with Chrome version 79.. Tells me that you're likely using incompatible versions of your driver.exe and chrome.

Seeing that you're using chrome version 79, you should fetch the chromedriver version that matches it https://chromedriver.chromium.org/downloads, which is 79.0.3945.36. You are using 78.0.3904.105 currently.

Even though the throw is happening on the get(url) method, which could make it seem like the website is contributing to this error, I believe this is coincidental and that the problem will occur on the first instruction to the browser, no matter which type that is.

Edit. This looks like a new issue. Verify that your xpath points to a valid element, and that the page is fully loading. For testing, I suggest trying to locate simpler xpath to a persistent part of the page near the root element, to verify that locating works generally. This exception suggests though that you're all set up, and that you need to start tuning to the site to get timing and locating working

Julian
  • 1,583
  • 1
  • 13
  • 31
  • Hi, I was hoping this was the case... Unfortunately, I updated my ChromeDriver to the link you provided and while the warning is now gone, the same error persists. I did try using the same code on other sites and I'm still getting the same error. – Martin Erlic Jan 20 '20 at 19:25
  • Could you edit your question to include the current log output at the bottom for comparison in case there's an updated clue hiding in there? – Julian Jan 20 '20 at 19:27
  • @MartinErlic I also see that there is a chromedriver version 80. You should verify that you don't have an available chrome update. If you're using an old version, then sometimes there can be bugs left over fixed in the following major update. – Julian Jan 20 '20 at 19:29
  • Hey, I've updated my question with the new exception. Chrome 80 has not been released officially yet, so that may be for an early release. The exception does in fact seem to be different now... ``Exception in thread "main" org.openqa.selenium.InvalidSelectorException``. But I'm trying to select elements all over the page and none of them seem to be responding. – Martin Erlic Jan 20 '20 at 19:37
  • @MartinErlic I updated my answer, but it looks like you noticed it too. I think you're browser problem is fixed and you're in the territory of tuning your code. I'm not sure how experienced you are with selenium so forgive me if I'm being pedantic. webdriver moves fast, real fast. It tries and sometimes works fairly well out of the box, but often times selenium will not wait for pages to load, and all parts of the dom to be rendered before performing actions, that's where your tuning comes in, to slow it down and give it the right things to wait for to be reliable – Julian Jan 20 '20 at 19:53
  • I am relatively experienced with Selenium. However, I think this goes beyond a tuning issue. I've experimented with longer loading times. This site doesn't seem to allow me to interact with anything, not even the logo in the top left corner... – Martin Erlic Jan 20 '20 at 19:55
  • Understood, is this new behavior repeatable on other sites as well? Or is this constrained to the one you're trying to work with? – Julian Jan 20 '20 at 19:56
  • This behavior is happening on other sites, including sites that I've successfully tested on before... For example, https://www.ccab.com/main/ccab_member/. – Martin Erlic Jan 20 '20 at 19:59
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/206306/discussion-between-martin-erlic-and-julian). – Martin Erlic Jan 20 '20 at 20:02
0

The first warning message...

[WARNING]: This version of ChromeDriver has not been tested with Chrome version 79

...was due to incompatibility between the version of the binaries as you were trying to initiate/spawn a new Browsing Context i.e. Chrome Browser session of:

  • chrome=79.0.3945.130 through
  • chromedriverVersion: 78.0.3904.105

Seems you have solved it by upgrading Chrome and ChromeDriver to identical levels.

You can find a detailed discussion in This version of ChromeDriver has not been tested with Chrome version 79 error running protractorE2E tests with ChromeDriver Chrome Selenium


The second error message ...

Exception in thread "main" org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression xpath=//a[contains(@href,'/property/search/hEC4ocSW0')] because of the following error:
TypeError: Failed to execute 'evaluate' on 'Document': The result is not a node set, and therefore cannot be converted to the desired type.

...implies that the Locator Strategy you have constructed was not a valid locator.

From your code attempts it is pretty evident the xpath in:

driver.findElement(By.xpath("xpath=//div[@id='__layout']/div/div[2]/section/div/table/tbody/tr/td")).click();

is mal-formatted.


Solution

As per the guidelines the ideal xpath expression should have been:

driver.findElement(By.xpath("//div[@id='__layout']/div/div[2]/section/div/table/tbody/tr/td")).click();

You can find a detailed discussion in InvalidSelectorError: invalid selector: Unable to locate an element with the xpath expression

DebanjanB
  • 118,661
  • 30
  • 168
  • 217