Can someone help me figure out how to click on a <td>
element that precedes the <td>
element with the linkText "Main" using Selenium? The element I'm looking to click is shown in the highlighted area of this image:
https://i.sstatic.net/QyHOt.png
Both the target <td>
element and the one following it are located within the same <tr>
element, as indicated by the image showing it with id=5
.
The element corresponds to the entire row highlighted below. It is identified by the linkText "Green," similar to the element below it. Therefore, I cannot use an xpath/css selector for the <td>
element I intend to click.
https://i.sstatic.net/BX244.png
My goal is to click on the highlighted "Green" element, which is why I need to target the <td>
element before the one with "Main" as its linkText.
I have the following code, but I am unsure how to locate the element preceding the one it currently matches:
WebElement templateFound = driver.findElement(By.linkText("Main"));
Any assistance would be greatly appreciated. Thank you.