Php-webdriver: click on the list of items | stale element reference: element is not attached to the page document

Created on 25 Apr 2018  Â·  9Comments  Â·  Source: php-webdriver/php-webdriver

Help. The task is to click on all the items in the list in turn.
On the second element in the list, call $element->click(); crashes.

HTML

<li class=" advancedLi li_lv_1" 
id="productCompare_Manufacturer_AMMANN"
onclick="selectManufacturer('AMMANN'); selectModel(null)"></li>
<li class=" advancedLi li_lv_1" 
id="productCompare_Manufacturer_AMMANN2"
onclick="selectManufacturer('AMMANN2'); selectModel(null)"></li>
... ... ...

php

$this->elements = $this->driver->findElements(WebDriverBy::className('advancedLi'));
foreach ($this->elements as $element) {
    $element->click();
}

console error

Facebook/WebDriver/Exception/StaleElementReferenceException with message 
'stale element reference: element is not attached to the page document
  (Session info: chrome=65.0.3325.181)
  (Driver info: chromedriver=2.35 (0),platform=Linux 4.16.2-1-MANJARO x86_64)'

  • Php-webdriver version: latest
  • PHP version: 7.2.4
  • Selenium server version: 3.11.0
  • Operating system: Linux 4.16.2-1-MANJARO x86_64
  • Browser used + version: chrome=65.0.3325.181

All 9 comments

I will be grateful if you give an example of how this can be done.
I'm just studying this tool.

For chrome v.65 cromedriver should be updated to v. 2.37 (you use 2.35)

On Wed, Apr 25, 2018 at 23:04 Dmitry Skibitsky notifications@github.com
wrote:

I will be grateful if you give an example of how this can be done.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/facebook/php-webdriver/issues/563#issuecomment-384416419,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFzhWBU90r8OkODLVTk7urUQ3BDWvSwIks5tsNbMgaJpZM4TkEUu
.

@klimart
On the second element in the list, call $element->click(); crashes.

Facebook/WebDriver/Exception/UnknownServerException with message 
'unknown error: Element <li class=" advancedLi li_lv_1" 
id="productCompare_Manufacturer_GEHL" 
onclick="selectManufacturer('GEHL'); selectModel(null)">...</li> 
is not clickable at point (503, 500). 
Other element would receive the click: 
<div class="cc_banner cc_container cc_container--open">...</div>  
(Session info: chrome=65.0.3325.181)
(Driver info: chromedriver=2.38.552522 
(437e6fbedfa8762dec75e2c5b3ddb86763dc9dcb),
platform=Linux 4.16.2-1-MANJARO x86_64)'

the first element being identical. But it could click on that element.

Regarding this error, I have similar in cases when some popup covers
required element you want to click, it can be search suggestions in my
case.
Regarding technology stack, it will work for you and this stack can resolve
any scraping needs

On Wed, Apr 25, 2018 at 23:45 Dmitry Skibitsky notifications@github.com
wrote:

@klimart https://github.com/klimart

On the second element in the list, call $element->click(); crashes.

Facebook/WebDriver/Exception/UnknownServerException with message 'unknown error: Element

  • ...
  • is not clickable at point (503, 500). Other element would receive the click:
    ...
    (Session info: chrome=65.0.3325.181) (Driver info: chromedriver=2.38.552522 (437e6fbedfa8762dec75e2c5b3ddb86763dc9dcb),platform=Linux 4.16.2-1-MANJARO x86_64)'

    —
    You are receiving this because you were mentioned.

    Reply to this email directly, view it on GitHub
    https://github.com/facebook/php-webdriver/issues/563#issuecomment-384428026,
    or mute the thread
    https://github.com/notifications/unsubscribe-auth/AFzhWKcsV-n-iYLw0-oclbdSezY1jag-ks5tsOBSgaJpZM4TkEUu
    .

    @klimart , Thank you. So far I have found another solution. Gathered the parameters for the js method which is onclick and passed it on execution in turn with a delay. But it would be safer to click. Since there I can control the appearance of the block on the page. Although if executeScript assumes that operations after this method will start only after executeScript is finished then this option looks reliable.

    AFAIU this error message is exactly what it says. Between your search and 2nd click something changes the DOM of the website (most probably the 1st click does) therefore the reference for the 2nd item you acquired as a result of findElements() method wasn't a part of DOM any more. You need to get new reference for each element in the loop (search for them again). This is unfortunately common for SPAs.

    @cprn I just noticed that it takes the coordinates for the click. In this case, it is true that it will not be able to get to the right element in any case. There, each click deploys a nested list and changes the position of the next item in the list of those that you want to click on. Thank you.

    Can we assume this was a website specific issue and the driver behaves correctly then? Can this be closed?

    @cprn yes, close

    Was this page helpful?
    0 / 5 - 0 ratings