[英]Find element by XPATH using Selenium with Python
I am trying to click various buttons on a page using Selenium (in combination with PhantomJS). 我正在尝试使用Selenium(与PhantomJS结合使用)单击页面上的各种按钮。 The html of the button looks like this:
该按钮的html如下所示:
<button class="btn btn-default btn-kudo btn-xs empty js-add-kudo" data-
entry="["Activity",1171944030]" str-on="click" str-trackable-
id="CgwIBTIICN7k6a4EGAESBAoCCAc=" str-type="kudos" title="Give Kudos">
<span class="app-icon icon-dark icon-kudo icon-sm">Kudos</span>
<span class="count count-kudos" data-kudo-count="0">0</span>
</button>
I want to click the buttons with certain Activity IDs that I define earlier in my script. 我想单击带有我先前在脚本中定义的某些活动ID的按钮。 Therefore, I would like to find the button using the XPATH of the data-entry.
因此,我想使用数据输入的XPATH查找按钮。 I tried the following:
我尝试了以下方法:
driver.find_element_by_xpath('//input[@data-entry="["Activity",1171944030]"]')
and 和
driver.find_element_by_xpath('//input[@data-entry="["Activity",1171944030]"]')
And a few variations putting the quotation marks in different positions, but none of them is able to find the element. 还有一些将引号放在不同位置的变体,但没有一个能够找到该元素。 Can anyone see what I am doing wrong?
谁能看到我在做什么错?
如果使用contains
则可以避免引号问题
driver.find_element_by_xpath("//button[contains(@data-entry, 'Activity')][contains(@data-entry, '1171944030')]");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.