Reputation: 67
I am trying to click various buttons on a page using Selenium (in combination with PhantomJS). The html of the button looks like this:
<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. Therefore, I would like to find the button using the XPATH of the data-entry. 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?
Upvotes: 0
Views: 9259
Reputation: 50919
You can avoid the quotation marks problem if you use contains
driver.find_element_by_xpath("//button[contains(@data-entry, 'Activity')][contains(@data-entry, '1171944030')]");
Upvotes: 1