-1

I'm trying to click this button highlighted in yellow with Selenium in Python

From this webpage: https://www.femina.fr/article/jeu-concours-spartoo-decembre-2020

I've passed both the cookies and allow/block notifications popups.

I'm trying in plain windows(?), I mean I'm not trying this in headless mode.

Tried with Chrome and Firefox webdriver: same results.

I've tried all the following without success:

driver.find_element_by_xpath("//input[@value='Jouer et s'inscrire !']").click()

driver.find_element_by_xpath("//input[@type='submit' and @value='Etape suivante']").click()

driver.find_element_by_xpath("//button[contains(., 'Jouer et s'inscrire !')]").click()

driver.find_element_by_xpath("//*[@id='jouerBtn']").click()

driver.find_element_by_xpath("/html/body/div[1]/div[3]/div/form/input[3]").click()

driver.find_element_by_css_selector("[type=submit]").click()

What am I doing wrong?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Try adding time sleep and also to get xpath right click button > inspect element > control click input > copy full xpath – Rocket Nikita Dec 29 '20 at 16:07
  • It's the 5th I've tried if you look at my code: driver.find_element_by_xpath("/html/body/div[1]/div[3]/div/form/input[3]").click() –  Dec 29 '20 at 16:16
  • Have you first clicked past the screen requesting that you accept cookies? And it would help if you 1. posted Minimal Reproducible Code 2. the exact error you are getting. – Booboo Dec 29 '20 at 16:31
  • @Booboo yes, I passed both the cookies and the allow/block notifications popups. I don't have much code yet because I won't code anything if I can't pass this button :) The error is pretty simple and the same for every method I tried: *no such element: Unable to locate element*. –  Dec 29 '20 at 16:39

3 Answers3

2

The button you are looking for is within an <iframe>, which you have to first switch to before you can do your find_element_by_xpath:

driver.switch_to.frame('qualifio-0136862F-D302-43A1-A613-F291B4D70337')

The simplest way to then find the button is:

driver.find_element_by_id('jouerBtn')
Booboo
  • 38,656
  • 3
  • 37
  • 60
1

The element Jouer et s'inscrire ! is within an <iframe> so you have to:

  • Induce WebDriverWait for the desired frame to be available and switch to it.

  • Induce WebDriverWait for the desired element to be clickable.

  • You can use either of the following Locator Strategies:

    • Using CSS_SELECTOR:

      driver.get('https://www.femina.fr/article/jeu-concours-spartoo-decembre-2020')
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button#didomi-notice-agree-button>span"))).click()
      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[id^='qualifio']")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#jouerBtn"))).click()
      
    • Using XPATH:

      driver.get('https://www.femina.fr/article/jeu-concours-spartoo-decembre-2020')
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[contains(., 'accepte')]"))).click()
      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[starts-with(@id, 'qualifio')]")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='jouerBtn']"))).click()
      
  • Note : You have to add the following imports :

     from selenium.webdriver.support.ui import WebDriverWait
     from selenium.webdriver.common.by import By
     from selenium.webdriver.support import expected_conditions as EC
    
  • Browser Snapshot:

femina_france


Reference

You can find a couple of relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
-1

Following XPaths are correct

driver.find_element_by_xpath("//*[@id='jouerBtn']").click()

driver.find_element_by_xpath("/html/body/div[1]/div[3]/div/form/input[3]").click()

Following XPaths/CSS are not correct

driver.find_element_by_xpath("//input[@value='Jouer et s'inscrire !']").click()

driver.find_element_by_xpath("//input[@type='submit' and @value='Etape suivante']").click()

driver.find_element_by_xpath("//button(contains(., 'Jouer et s'inscrire!')]").click() 
driver.find_element_by_css_selector("[type=submit]").click()

The element (button) is not in the visible area of the screen. Hence element should be brought into the visible area before clicking.

Corrections to the location syntax

driver.find_element_by_xpath("//input[@value=\"Jouer et s'inscrire !\"]").click()

driver.find_element_by_xpath("//input[@type='button' and @value=\"Jouer et s'inscrire !\"]").click()

driver.find_element_by_xpath("//input[contains(@value, 'Jouer et s')]").click() 
driver.find_element_by_css_selector("[type='button']").click()
Janesh Kodikara
  • 1,670
  • 1
  • 12
  • 23