selenium:使用python单击动态单选按钮

时间:2016-06-27 23:55:28

标签: python selenium

我正在尝试点击动态网页上的单选按钮。我尝试了classname,xpath,没有任何效果。

包含单选按钮的代码是:

<input id="radiofield-1247-inputEl" class="x-form-field x-form-radio x-form-cb" type="button" hidefocus="true" autocomplete="off" role="radio">

按钮旁边有一个标签。

<label id="radiofield-1247-boxLabelEl" class="x-form-cb-label x-form-cb-label-after" for="radiofield-1247-inputEl">Yes</label>

我试过了:

driver.find_element_by_xpath("//*[@type='radio'][@class='#class here'") #.click() and this doesn't work. 

我尝试传递绝对xpath,但也失败了。没有名称或ID可供搜索。

1 个答案:

答案 0 :(得分:0)

您在提供type="radio"HTML type="button"正在尝试XPath ...

尝试关注driver.find_element_by_xpath('//input[contains(@id, "radiofield-")][@role="radio"]')

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
   http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion> 4.0.0 </modelVersion>
    <groupId> com.tp.neo4j </groupId>
    <artifactId> springdata-neo4j </artifactId>
    <version> 1.0 </version>

    <dependencies>
        <dependency>
            <groupId> org.springframework.data </groupId>
            <artifactId> spring-data-neo4j </artifactId>
            <version> 3.1.2.RELEASE </version>
        </dependency>
    </dependencies>
</project>