Reputation: 11
I tried to click on a "Ok" Button with selenium and it simply doesn't work.. I am able to click on any other button except this one. Here is the class:
<button class="button-1iktpaT1 size-l-2NEs9_xt intent-primary-1-IOYcbg appearance-default-dMjF_2Hu actionButton-3wPv1Zy2 small-3wPv1Zy2" name="ok"><span class="content-2PGssb8d"><span class="">Ok</span></span></button>
I tried with this :
self.driver.find_element_by_xpath('//span/span[contains(text(),\'Ok\')]/parent::button').click()
It works with others buttons.. Anyone have the solution? thanks a lot!
Upvotes: 1
Views: 55
Reputation: 33
you could try using different 'searching' methods like
self.driver.find_element_by_name
orself.driver.find_element_by_class
orself.driver.find_element_by_id
With one of these methods you should be able to click the button.
Upvotes: 0
Reputation: 242
Easy Peezy:
self.driver.find_element_by_name('ok')
OR
self.driver.find_element(By.CSS_SELECTOR, 'button[name="ok"]')
It's better to search by the id, name, or class of an element than the text when possible.
Upvotes: 1