1

I want to go from this page to this https://resultats.ffbb.com/organisation/b5e6211d5970.html to this page https://resultats.ffbb.com/championnat/b5e6211f621a.html?r=200000002810394&d=200000002911791&p=2 by clicking on 'Régional féminin U15'. I have tried many solutions but the best I had, is not working systematically. Please coul you help me?

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

driver = webdriver.Firefox()
driver.get("https://resultats.ffbb.com/organisation/b5e6211d5970.html")

driver.switch_to.frame("idIframeChampionnat")
#sign_in = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '/html/body/pre/span[93]'))).click();

button = driver.find_element_by_partial_link_text(u"minin U15")
button.click()```
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Elmanu20
  • 13
  • 3

2 Answers2

0

Try

driver.switch_to.frame("idIframeChampionnat")
button = driver.find_element_by_xpath("//a[contains(text(), 'minin U15')]")
button.click()

or

driver.switch_to.frame("idIframeChampionnat")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[contains(text(), 'minin U15')]"))).click()

This is my code example in groovy (sorry, haven't python env), pretty similar to yours, and it works perfectly 20 times in a loop even without timeouts.

    @Test(invocationCount = 20)
    void test() {
        driver.get('https://resultats.ffbb.com/organisation/b5e6211d5970.html')
        driver.switchTo().frame(
                driver.findElement(By.xpath("//iframe[@id='idIframeChampionnat']"))
        )
        driver.findElement(By.xpath("//a[contains(text(), 'minin U15')]")).click()
        driver.switchTo().defaultContent()
        assert driver.getCurrentUrl() ==
                'https://resultats.ffbb.com/championnat/b5e6211f621a.html?r=200000002810394&d=200000002911791&p=2'
    }

So, I have no ideas. Maybe just add driver.switch_to.default_content() after click?

Max Daroshchanka
  • 2,698
  • 2
  • 10
  • 14
0

To click() on the link with text as Régional féminin U15 as the elements are 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://resultats.ffbb.com/organisation/b5e6211d5970.html")
      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe#idIframeChampionnat")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "Régional féminin U15"))).click()
      
    • Using XPATH:

      driver.get("https://resultats.ffbb.com/organisation/b5e6211d5970.html")
      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@id='idIframeChampionnat']")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "Régional féminin U15"))).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:

resultats


Reference

You can find a couple of relevant discussions in:

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