0

I am doing some automation script for the website https://silkdb.bioinfotoolkits.net in selenium using python languageenter image description here where I have you can see a button named "Blast" that pops up a window with some default values on click.

<div data-meta="Field" id="program" role="radiogroup" class="next-radio-group next-radio-button next-radio-button-medium">
<label dir="ltr" aria-checked="true" class="next-radio-wrapper checked "><span class="next-radio-single-input">
   <input role="radio" tabindex="0" type="radio" aria-checked="true" class="next-radio-input"></span><span class="next-radio-label">blastn</span>
</label>

<label dir="ltr" aria-checked="false" class="next-radio-wrapper "><span class="next-radio-single-input">
<input role="radio" tabindex="-1" type="radio" aria-checked="false" class="next-radio-input"></span><span class="next-radio-label">blastx</span></label>

<label dir="ltr" aria-checked="false" class="next-radio-wrapper "><span class="next-radio-single-input"><input role="radio" tabindex="-1" type="radio" aria-checked="false" class="next-radio-input"></span><span class="next-radio-label">tblastn</span></label>

<label dir="ltr" aria-checked="false" class="next-radio-wrapper "><span class="next-radio-single-input"><input role="radio" tabindex="-1" type="radio" aria-checked="false" class="next-radio-input"></span><span class="next-radio-label">blastp</span></label></div>

The default label named "blastn" is selected on defualt. But I want to select lable named "blastp".

I have tried many things using xpath but I am unable to get it selected.

Please help me in this. enter image description here

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

3 Answers3

0

To click on the element you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    driver.get("https://silkdb.bioinfotoolkits.net/")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button#btn-blast"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div#program label:last-child span:nth-child(2)"))).click()
    
  • Using XPATH:

    driver.get("https://silkdb.bioinfotoolkits.net/")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@id='btn-blast']"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[@class='next-radio-label' and text()='blastp']"))).click()
    
  • Note : You have to add the following imports:

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

Browser Snapshot:

blastp

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

It is important to send the click events to the appropriate receiving elements which can actually react to the click event. In this case, i think the click must be send to the input element, not the span. Please try with the following xpath.

//span[@class="next-radio-label" and contains(text(),'blastp')]/preceding-sibling::span/input
Sureshmani Kalirajan
  • 1,938
  • 2
  • 9
  • 18
0

Please use following xpath to click your option //span[contains(text(),'blastp')]

Justin Lambert
  • 940
  • 1
  • 7
  • 13