0

I am working on a python selenium code to try to click a radio button. Here is the html code:

<tbody>
   <tr class="row-event">
      <td class="selection-cell"><input type="radio" class=""></td>
      <td>812589</td>
      <td>john</td>
   </tr>
   <tr class="row-event">
      <td class="selection-cell"><input type="radio" class=""></td>
      <td>909720</td>
      <td>bob</td>
   </tr>
</tbody>

I want to click the radio-button where it is of the same row that containing "812589" value. How may this "target" being defined in the following code.

def clickTargetRadio(self):
    by = By.XPATH
    target = ""   # ???
    WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((by, target))).click()

1 Answer 1

1

You can use the following XPath :

//td[.='812589']/preceding-sibling::td[1]/input

We look for an input element, child of the first td preceding-sibling of a td element containing 812589.

Imports :

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

Code :

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//td[.='812589']/preceding-sibling::td[1]/input"))).click()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.