硒按钮,同一个类别,带有多个“

时间:2019-02-05 21:41:21

标签: python selenium button onclick buttonclick

我试图点击“攻击”按钮。有四个带有相同文本的按钮。有代码正在处理,但我无法确定它。你能帮我选择我想要的任何按钮吗?感谢您的帮助...

按钮1:

<button class="expedition_button awesome-button " onclick="attack(null, '2', 1, 0, '')">Attack</button>

按钮2:

<button class="expedition_button awesome-button " onclick="attack(null, '2', 2, 0, '')">Attack</button>

按钮3:

<button class="expedition_button awesome-button " onclick="attack(null, '2', 3, 0, '')">Attack</button>

按钮4:

<button class="expedition_button awesome-button " onclick="attack(null, '2', 4, 0, '')">Attack</button>

我在下面尝试了这些代码

        self.web.find_element_by_xpath("(//button[@class=expedition_button awesome-button 'Attack'])[3]")

我也想学习以前如何使用任何定义的数据,而不是类名或按钮名或ID。?

2 个答案:

答案 0 :(得分:0)

要获取特定的按钮,请尝试使用类和索引,或者尝试使用文本和索引,只要您愿意就可以。

<int:channel id="requestChannelPreEdit">
    <int:queue capacity="100"/>
</int:channel>

<int:poller id="defaultPoller"
    default="true"
    fixed-delay="50"
    receive-timeout="5000">
</int:poller>

<bean id="headerSerializer"
    class="CustomByteArrayLengthHeaderSerializer">
</bean>

<int-ip:tcp-connection-factory id="serverFactory"
    type="server"
    port="6060"
    serializer="headerSerializer"
    deserializer="headerSerializer"/>

 <int-ip:tcp-inbound-channel-adapter id="inboundRequestAdapter"
    channel="requestChannelPreEdit"
    connection-factory="serverFactory"/>

<bean id="requestEditor"
    class="RequestEditor"/>

<int:service-activator id="requestEditorSA"
    input-channel="requestChannelPreEdit"
    ref="requestEditor"
    method="editRequest"/>

对于Button1:

driver.find_element_by_xpath("(//button[text()[contains(.,'Attack')]])[indexval]")
driver.find_element_by_xpath("(//button[@class='expedition_button awesome-button '])[indexval]")

OR

driver.find_element_by_xpath("(//button[text()[contains(.,'Attack')]])[1]")

与按钮2,3和4类似,只是增加索引值。

答案 1 :(得分:0)

另一种方法。

{400000, 300000, 250000, 550000}