I have a very simple script that find all HREF in a page and iterate and logs it:
Photo search scroll
Go To https://xxx
${elements}= Get WebElements xpath://a[contains(@href,'photo')]
FOR ${element} IN @{elements}
Log ${element.get_attribute('href')}
END
It works perfectly fine. As I need to open a new browser for each of HREF I added Selenium Browser command:
Photo search scroll
Go To https://xxx
${elements}= Get WebElements xpath://a[contains(@href,'photo')]
FOR ${element} IN @{elements}
Log ${element.get_attribute('href')}
Go To ${element.get_attribute('href')}
sleep 2s
Capture Page Screenshot
Go Back
END
I always get this error after first iteration:
Resolving variable '${element.get_attribute('href')}' failed: StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
(Session info: chrome=86.0.4240.111)
I'm unable to figure out why this happen. Any help/comments is appreciated. Many Thanks
###UPDATE I've created a list varible and addedd additional loop:
@{hrefs} = Create List
FOR ${element} IN @{elements}
Log ${element.get_attribute('href')}
Append To List ${hrefs} ${element.get_attribute('href')}
END
FOR ${href} IN @{hrefs}
Go To ${href}
sleep 2s
Capture Page Screenshot
END
now I obtain this error code:
Opening url 'Create List'
20:08:36.739 FAIL InvalidArgumentException: Message: invalid argument
(Session info: chrome=86.0.4240.111)
