Samuel Duclos
Samuel Duclos

Reputation: 11

Struggle to click on a ''Ok'' button with selenium in Python

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

Answers (3)

Paul Recker
Paul Recker

Reputation: 33

you could try using different 'searching' methods like

self.driver.find_element_by_name or self.driver.find_element_by_class or self.driver.find_element_by_id

With one of these methods you should be able to click the button.

Upvotes: 0

Ryan Nygard
Ryan Nygard

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

Prophet
Prophet

Reputation: 33361

Try this xpath //button[@name='ok']

Upvotes: 2

Related Questions