Specifying Row on Page

I have a list of rows in a table on one of my screens (see below) that I need to select a button (circled in red) on that specific row. However, the row may not be in the same position on the screen the next time the test is run. It might be the first row from the top on the initial test run but third from the top on the next test run. Is there a way I can run the test to activate the Reset button related to a specific Batch Name regardless of the row position it is within the table? Thank You

Yes, but we’ll need more information. Please follow this advice:

I did look at that information before submitting my post. I am sending the HTML related to the table below, if I am missing something else that is needed please let me know what you need. Thanks for your help.

I promise you this is easy to do. But I think you should use XPath to find the relevant row and I never use XPath… so I’m handing you over to @Brandon_Hein

WebDriver driver = DriverFactory.getWebDriver()
int rowCount = driver.findElements(By.xpath("//table//tbody//tr")).size()
for(int i = 1; i <= rowCount.size(); i++) {
    String batchName = driver.findElement(By.xpath("//table//tbody//tr[" + i + "]/td[1]")).getText()
    if(batchName.equals("some batch name")) {
        driver.findElement(By.xpath("//table//tbody//tr[" + i + "]/td[6]//button[normalize-space()='Reset']")).click()
        break
    }
}

Something like that. I don’t see all the HTML for the table, so I just assumed it was the only one on the page at that time.

Thank you I will give that a try. I appreciate it.

I had a few undefined problems but was able to correct them with the following imports.

import org.openqa.selenium.WebDriver as WebDriver
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory

But now I have run into the following error and have looked but cannot find the resolution or how to clear up my By problem…
Test Cases/InsertAfter Lightning Rule FAILED.
Reason:
groovy.lang.MissingPropertyException: No such property: By for class: Script1588352035941
at InsertAfter Lightning Rule.run(InsertAfter Lightning Rule:37)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1588353750584.run(TempTestCase1588353750584.groovy:25)

Thanks Again

Ok I found the solution. I added the following and it seems to be working great.

import org.openqa.selenium.By as By

Many thanks!!!

1 Like