Reputation: 2389
EDIT: a few seconds after page loads a cookies warning gets added to the page (which I didn't notice before, and of course I accepted it manually in my browser a long time ago)... which, I guess, invalidates whatever happened before that. so I just added wait after the get() and its all good now.
stale element reference: element is not attached to the page document
error while looping over WebElements found with find_elements()
after the first element.
Trying to run this simple script
use strict;
use warnings;
use feature qw/say/;
use Selenium::Chrome;
my $driver = Selenium::Chrome->new( binary => 'C:/path-to/chromedriver.exe' );
$driver->get( 'https://...' );
my $pdf_links = $driver->find_elements('//a[@class="file-link"]');
for my $link (@$pdf_links) {
my $filename = $driver->find_child_element($link, "./span")->get_text();
say $filename;
}
and I get this error:
first-file-name.pdf
Error while executing command: stale element reference: element is not attached to the page document
(Session info: chrome=75.0.3770.100)
(Driver info: chromedriver=75.0.3770.90 (a6dcaf7e3ec6f70a194cc25e8149475c6590e025-refs/branch-heads/3770@{#1003})
,platform=Windows NT 10.0.18362 x86_64) at C:/<path>/perl/perl/site/lib/Selenium/Remote/Driver.pm line 403.
at C:/<path>/perl/perl/site/lib/Selenium/Remote/Driver.pm line 353.
The @$pdf_links
has over 160 elements, but find_child_element()
only works on 1st iteration.
Upvotes: 0
Views: 100
Reputation: 2389
А few seconds after page loads a "cookies warning" gets added to the page (which I didn't notice before, and, of course, I accepted it manually in my browser a long time ago)... which, I guess, invalidates whatever happened before that. So, I just added a wait after the get()
and its all good now.
Upvotes: 1