Nuclearz
Nuclearz

Reputation: 25

Can't click on this button selenium webdriver python

I'm trying to click on this button from hours, no way to do it. I tried to find it in all ways XPATH exc.. The button is inside an iframe "iframeGioco" i also switched to it, but still nothing.

Please help me out.

This is the html source:

enter image description here

I need to click on the highlighted div that is a button or in the next div contains "OK".

I did a lot of scripts with selenium but this button is really hard to click. I would link the page but i can't, because you should have an eurobet account to see this page.

Thank you.

example of my tries:

browser.switch_to_frame(browser.find_element(By.XPATH,'//iframe[@id="iframeGioco"]'))

browser.find_element(By.XPATH,"//div[@class='rounded-corners no-highlight ftl-error-buttonise absolute-horz-center']").click()

NB: THE STRANGE THING IS THAT I DON'T GET AN ERROR LIKE "NOSUCHELEMENT" I DON'T GET NOTHING, SO I THINK THE ELEMENT IS FOUND BUT THE CLICK DOESN'T WORK FOR SOME REASON.

NEED TO CLICK "OK" BUTTON

THE BUTTON TO CLICK IS THE "OK" BUTTON IN THE IMG.

Upvotes: 1

Views: 424

Answers (2)

Muzzamil
Muzzamil

Reputation: 2881

You can try to click with JS as it work differently.

Webdriver work as we/user do manually. If element is not enabled even user can see it on page it will not click while JS is client side script and it talk to directly browser (with help of built in interpreter)

Please try with below code.

driver.execute_script("arguments[0].click();", webElement)

Upvotes: 2

KunduK
KunduK

Reputation: 33384

To click on OK div element which is inside an iframe

Induce WebDriverWait() and frame_to_be_available_and_switch_to_it()

Induce WebDriverWait() and element_to_be_clickable() and following Xpath

WebDriverWait(browser,20).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"iframeGioco")))
WebDriverWait(browser,20).until(EC.element_to_be_clickable((By.XPATH,"//div[text()='OK']"))).click()

OR

WebDriverWait(browser,20).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"iframeGioco")))
WebDriverWait(browser,20).until(EC.element_to_be_clickable((By.XPATH,"//div[contains(.,'OK')]"))).click()

You need to add following libraries.

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

UPDATE

Induce Javascript executor to click.

WebDriverWait(browser,20).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"iframeGioco")))
browser.execute_script("arguments[0].click();", WebDriverWait(browser,20).until(EC.presence_of_element_located((By.XPATH,"//div[contains(.,'OK')]"))))

Upvotes: 2

Related Questions