1

I was asked this question on interview. I need to perform click action on "open" button which is opposite to "CLR-9194":

enter image description here

I told that with help of index I can perform action on that particular "open" button:

findElement(By.xpath("//label[2]"))

But he told me that I was wrong.

Jackie M
  • 65
  • 7
  • 3
    Your task was given in terms of the cell content, `CLR-9194`, so any solution not even containing a reference to that specified content, must be wrong. The visual appearance was given as an illustration, not an invitation to write code that only works if the page looks exactly like that. – Holger Sep 14 '22 at 08:29
  • Post the relevant html of the table? – KunduK Sep 14 '22 at 08:53

1 Answers1

1

You need to locate the table row parent element based on the CLR-9194 content and then to find the open button child element of that row.
So, if each table row is td element (it can be tr, I don't know, you did not share the XML) and the open element is "label" the XPath can be something like this:

"//td[contains(.,'CLR-9194')]//label"

The Selenium code will be correspondingly something like:

findElement(By.xpath("//td[contains(.,'CLR-9194')]//label"))

the XPath above can and should be made more precise. We need to see the XML for that.

Prophet
  • 32,350
  • 22
  • 54
  • 79