如何使用python单击硒中下方的广播中的输入角色 [英] How to click an input role as radio located under in selenium using python

查看:56
本文介绍了如何使用python单击硒中下方的广播中的输入角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用硒为硒中的网站在这里,您可以看到名为爆炸"的按钮,会弹出一个带有一些默认值的窗口.

 < div data-meta =字段"id =程序"角色=无线电组"类别=下一个无线电组下一个无线电按钮下一个无线电按钮中等".< label dir ="ltr"aria-checked ="true"类别=下一个无线电包裹器已检查""span类别=下一个无线电单个输入"<输入角色=无线电".tabindex ="0"type ="radio"aria-checked ="true"类别=下一个无线电输入"/span类别=下一个无线电标签"/blastn/span</label>< label dir ="ltr"aria-checked ="false"class =下一个无线电包""span class ="下一个无线电单输入"<输入角色=无线电".tabindex =-1";type ="radio"aria-checked ="false"类别=下一个无线电输入"/span类别=下一个无线电标签"/blastx//span/标签< label dir ="ltr"aria-checked ="false"类别=下一个无线电包裹器">跨度"类别=下一个无线电单个输入">输入角色="无线电"tabindex =-1";type ="radio"aria-checked ="false"class =下一个无线输入"/span class ="next-radio-label"/tblastn/span/label< label dir ="ltr"aria-checked ="false"类别=下一个无线电包裹器">跨度"类别=下一个无线电单个输入">输入角色="无线电"tabindex =-1";type ="radio"aria-checked ="false"class =下一个无线输入"/span class =下一个无线标签"/blastp/span/标签/div 

名为"blastn"的默认标签为被选择为默认值.但我想选择名为"blastp"的标签.

我已经尝试过使用xpath进行很多操作,但是我无法选择它.

请帮助我.

解决方案

要单击该元素,您必须引入

I am doing some automation script for the website 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.

解决方案

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:

这篇关于如何使用python单击硒中下方的广播中的输入角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆