1

Problem

I'm trying to execute a Katalon script. The goal is to check if the field contains a specific value. I use a loop to browse all of the table. However, I don't understand the error.

Moreover, the error does not always occur at the same time. Sometimes it occurs during the first loop iteration, sometimes on the third.

Versions

  • Katalon 5.4
  • Chrome 67

Error

Test Cases/test FAILED because (of)
org.openqa.selenium.StaleElementReferenceException: stale element
reference: element is not attached to the page document 
...
*** Element info: {Using=xpath, value=.//td[4]/a}

Katalon Code

List<WebElement> elements = driver.findElements(By.xpath('//*[@id="id1"]//tr[td/a]'))
for (element in elements) {
    ...
    if (!excelValue.equals(CustomKeywords.'datadriven.DataDriven.getValueFromExcel'('Sheet1', 'ColumName', 1))) {
        element.findElement(By.xpath('.//td[4]/a')).click()
        def webvalue = WebUI.getAttribute(findTestObject(object1), 'value')
        WebUI.verifyEqual(webvalue.contains(excelValue), true)
        WebUI.click(findTestObject(object2))
    }
}

HTML Code

<div id='id1'>
    <table>
        <tbody>
            <tr></tr>
            <tr>
                <td>value 1</td>
                <td>value 2</td>
                <td>value 3</td>
                <td><a> ... </a></td> // a link here
                <td>value 5</td>
                ...
            </tr>
            <tr></tr>           
            <tr>
                <td>value 1</td>
                <td>value 2</td>
                <td>value 3</td>
                <td><a> ... </a></td> // a link here
                <td>value 5</td>
                ...
            </tr>
            <tr></tr>
            ...
        </tbody>
    </table>
</div>

Already tried

Thanks for your help!

Solution 1

This problem is due to references which are after the page refresh.

The solution I found is to create the object with a for 'loop'.

List<WebElement> elements = driver.findElements(By.xpath('//*[@id="id1"]//tr[td/a]'))
for(int i = 1; i <= elements.size(); i++) {
    WebElement element = driver.findElement(By.xpath('//*[@id="id1"]//tr[td/a][' + i + ']')) {
}
Mihai Chelaru
  • 7,614
  • 14
  • 45
  • 51
Royce
  • 1,557
  • 5
  • 19
  • 44
  • Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackoverflow.com/rooms/177035/discussion-on-question-by-n-lamblin-error-stale-element-reference-element-is). –  Jul 30 '18 at 14:39
  • @cruisepandey Actually if watch this carefully here, webdriver itself is longing for two condition before it performs any action, so webdriver itself must have provided the way to wait through implicit wait, actually it was there in legacy driver but it's not there in geckodriver, so after realizing this I raised a bug in geckodriver, here is the link https://github.com/mozilla/geckodriver/issues/960 people agreed with me but haven't done any thing after that(continued..) – Rajagopalan Jul 30 '18 at 14:41
  • @cruisepandey So If we move WATIR which sits on the top of selenium does these checking perfectly before it triggers any action so WATIR is the best option atleast for a website which continue change quickly! – Rajagopalan Jul 30 '18 at 14:42

0 Answers0