Home > database >  Target the correct edit link next to certain item using Python Selenium
Target the correct edit link next to certain item using Python Selenium

Time:01-01

This is my first ever post.

I have recently started using Python and Selenium to do some administrative work on several websites. All websites have the same domain and are setup in a similar way.

After searching online for about a week now I wasn't able to find anything related to the following issue. I will try to explain the problem I'm facing:

website 1:

Apple   Remove  Edit Copy
Banana  Remove  Edit Copy
Pear    Remove  Edit Copy

website 2:

Banana  Remove  Edit Copy
Pear    Remove  Edit Copy
Apple   Remove  Edit Copy

How can I make selenium click the edit link for instance for the item Pear? For website 1 it is the edit link no. 3 and for website 2 it is edit link no.2

html code websites

Is it in some way possible to make Selenium go to the edit link relative (to the right of) to the item Pear?

I hope my question is clear and someone is able to point me in the correct direction.

Thank you.

CodePudding user response:

you can filter for name ->

if driver.find_element_by_xpath('//*[@id="DwsldCn"]/div/table/tbody/tr[1]/td[4]/a').get_attribute("name")=="banana": print("perfect"

CodePudding user response:

Try this:

driver.find_element_by_xpath("//span[contains(@id, 'ItemName')][text()='Pear']/following::a[contains(@id, 'lnkEdit')]")

  • Related