1

I'm new to Selenium/Katalon and I'm having trouble with my script. I'm getting an "unable to locate element" for my table element that I have specified.

I'm not sure if I'm referencing the wrong xpath/id, any help would be great.

Script:


WebDriver driver = DriverFactory.getWebDriver()

WebUI.waitForElementClickable(findTestObject('input'), 0)
//Locate EE ID
WebElement Table = driver.findElement(By.id("ctl00"))

List<WebElement> Rows = Table.findElements(By.className("Row"))

println('No. of rows: ' + Rows.size())

table: for (int i = 0; i < Rows.size(); i++) {
    List<WebElement> Cols = Rows.get(i).findElements(By.tagName('td'))

    for (int j = 0; j < Cols.size(); j++) {
        if (Cols.get(j).getText().equalsIgnoreCase(ExpectedValue)) {
            Cols.get(4).findElement(By.xpath('//*[@id="ctl00')).click()

            break
        }
    }
}
Miracccle
  • 11
  • 2
  • Welcome, please post your code directly, and not as screenshot. This will greatly increase your chances of getting help. – Thomas Hirsch Feb 18 '21 at 19:56

1 Answers1

0

As mentioned in my comment, this question could be improved, and I urge you to still familiarise yourself with proper formatting. You also fail to actually mention which element you are looking or, so the reader has to guess it from your code, which could be misleading.

From briefly looking at the code and the screenshot, my guess is that your problem is that the single slash / in an XPath expression only matches direct children. So //*[@id="something"]/td would only match a td that is directly inside the element with the matching id attribute, which is the div outside the table.

Try either

//*[@id="something"]//td

with a double slash //, or something like

//*[@id="something"]/table/tbody/tr/td
Thomas Hirsch
  • 2,102
  • 3
  • 19
  • 39