Reputation: 69
I have create a simple bot that at the entry of the betfair website will simply click the accept cookies button. Its been working for months but now all of a sudden once entered the page, it will just keep loading without performing the action. Any idea why?
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
import time
url = r"C:\Users\salde\Desktop\chromedriver_win32 (1)\chromedriver.exe"
driver = webdriver.Chrome(executable_path=url)
##website to navigate to
driver.get('https://www.betfair.com/exchange/plus/')
##to accept cookies at the entry to the website
element = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH, '//*[@id="onetrust-accept-btn-handler"]'))
)
element.click()
time.sleep(2)
btnCookies = driver.find_element_by_xpath('//*[@id="onetrust-accept-btn-handler"]')
btnCookies.click()
Upvotes: 0
Views: 506
Reputation: 3717
As you've defined them, your variables element
and btnCookies
target the same element, and you shouldn't need to click it twice. (In fact the second time, the element is now longer displayed, which is why you get the element not interactable
error. At least try cleaning up your code to remove these last few lines and see what happens:
time.sleep(2)
btnCookies = driver.find_element_by_xpath('//*[@id="onetrust-accept-btn-handler"]')
btnCookies.click()
Upvotes: 1