2

I have the following code:

from selenium import webdriver
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select, WebDriverWait
from selenium.common.exceptions import TimeoutException

driver = webdriver.Firefox()
driver.get('https://www.flashscore.co.uk/tennis/atp-singles/australian-open-2021/results')
wait = WebDriverWait(driver, 5)
try:
    wait.until(EC.element_to_be_clickable((By.XPATH, "//button[@id='onetrust-accept-btn-handler']"))).click()
except TimeoutException:
    pass
exit_loop = False
while not exit_loop:
    try:
        wait.until(EC.element_to_be_clickable((By.XPATH, f"//a[@class='event__more event__more--static']"))).click()
    except TimeoutException:
        exit_loop = True

The first try/except block is to get rid of a 'privacy' banner that causes a ElementClickInterceptedException error and it works fine. However, I'm still getting one of the following two similar errors on the next try/except block in the while loop:

Exception has occurred: ElementClickInterceptedException
Message: Element <a class="event__more event__more--static" href="#"> is not clickable at point (623,976) because another element <span class="loadingOverlay"> obscures it

or:

Exception has occurred: ElementClickInterceptedException
Message: Element <a class="event__more event__more--static" href="#"> is not clickable at point (623,976) because another element <div id="onetrust-banner-sdk" class="otFlat ot-iab-2 bottom vertical-align-content ot-buttons-fw"> obscures it

I've tried adding another try/except block for the second error:

try:
    wait.until(EC.element_to_be_clickable((By.XPATH, "//div[@id='onetrust-banner-sdk']"))).click()
except TimeoutException:
    pass

However this doesn't work. I suspect I can't click this element so am on the wrong track...

As neither of the elements in the errors seem to be buttons I can click - how should I deal with them?


Edit:

I have updated the code to include scrolling:

driver = webdriver.Firefox()
driver.maximize_window()
driver.get('https://www.flashscore.co.uk/tennis/atp-singles/australian-open-2021/results')
wait = WebDriverWait(driver, 5)
try:
    wait.until(EC.element_to_be_clickable((By.XPATH, "//button[@id='onetrust-accept-btn-handler']"))).click()
except TimeoutException:
    pass
driver.execute_script("var scrollingElement = (document.scrollingElement || document.body);scrollingElement.scrollTop = scrollingElement.scrollHeight;")
exit_loop = False
while not exit_loop:
    try:
        wait.until(EC.element_to_be_clickable((By.XPATH, "//a[@class='event__more event__more--static']"))).click()
    except TimeoutException:
        exit_loop = True

However, I got each of the errors on the two runs I tried.

1 Answer 1

1

Jossy,

You need to scroll down till end of the page, before clicking on show more matches

code to scroll down :

driver.execute_script("var scrollingElement = (document.scrollingElement || document.body);scrollingElement.scrollTop = scrollingElement.scrollHeight;")

and then you can have this code :

wait.until(EC.element_to_be_clickable((By.XPATH, f"//a[@class='event__more event__more--static']"))).click()

You should launch broswer in full screen also :

driver.maximize_window()

before loading the URL.

Update 1 :

driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://www.flashscore.co.uk/tennis/atp-singles/australian-open-2021/results")
wait = WebDriverWait(driver, 10)
try:
    wait.until(EC.element_to_be_clickable((By.XPATH, "//button[@id='onetrust-accept-btn-handler']"))).click()
except TimeoutException:
    pass
exit_loop = False
while not exit_loop:
    try:
        driver.execute_script("var scrollingElement = (document.scrollingElement || document.body);scrollingElement.scrollTop = scrollingElement.scrollHeight;")
        sleep(1)
        wait.until(EC.element_to_be_clickable((By.XPATH, "//a[@class='event__more event__more--static']"))).click()
    except TimeoutException:
        exit_loop = True
Sign up to request clarification or add additional context in comments.

9 Comments

Thanks! I presume I need to figure out what the 'scrolling elements' are? I can't just copy your code?
You can copy paste exact code, no need to change anything, place it just before while loop
Ok, thanks. Getting the same two errors - updated the OP with your additions
Works great and with Firefox too :) Amended slightly as it didn't need a 5 second gap
no that driver.maximize_window() should maximize the window irrespective of headless or not.. try putting sleep little more .. and I would also like to know what is the exception
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.