0

I am currently developing an webdriver automation tool to perform a task in which I have to interact with a huge amount of elements. To do so, I am using Python 3.6.3, Selenium and Pandas.

One of these elements occurs to be a button that appears multiple times in the same screen. The problem is, only one of those buttons is the one I have to click on and there is no difference between them, except for its xpath (which changes everytime the page is refreshed).

The only way to know which one is the correct is by identifying the text contente of its simbling elements, which describes what the button in supposed to do. I managed to reach this element using:

element=driver.find_elements_by_xpath("//*[contains(text(),'"+textvariable+"')]")

But now I am stuck! How can I tell Selenium to click the button knowing only the text contente of its sibling?

Pedro Martins de Souza
  • 1,406
  • 1
  • 13
  • 35
  • 2
    This might be what you need: https://stackoverflow.com/questions/18079765/how-to-find-parent-elements-by-python-webdriver – Sasha Jun 07 '18 at 15:23
  • 1
    To further enforce the link @Jaxi directed you to, you'd find the sibling element, navigate to the parent, and then find the child button element from that. – tblznbits Jun 07 '18 at 15:25
  • Seems like a solution! But once I have the parent, how do I get the child button I want? – Pedro Martins de Souza Jun 07 '18 at 15:31
  • Pseudo-code: for child in parent: if child.text == 'textYouAreLookingFor': do stuff with child button element – natn2323 Jun 07 '18 at 15:36
  • 1
    Please show HTML code in question (not in comment and not by screenshot) – yong Jun 07 '18 at 15:59
  • Already solved it. The Button I needed was present in a table, so I used Pandas to get the entire table and then find what I wanted. Anyway, thank you guys :) – Pedro Martins de Souza Jun 11 '18 at 18:50

0 Answers0