I'm trying to enter a website with python (selenium) code and I'm required to accept cookies. For some reason, no matter what I've tried, I always get the result: Unable to locate element. Below 'accept cookies button' from the website's HTML code.
<button tabindex="0" title="Hyväksy kaikki evästeet" aria-label="Hyväksy kaikki evästeet" class="message-component message-button no-children buttons-row" path="[0,3,1]">Hyväksy kaikki evästeet</button>
I've tried the following:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from time import sleep
import pandas as pd
import requests as req
class trackerBot():
def __init__(self):
self.driver = webdriver.Chrome()
# Tried with and without implicitly wait
self.driver.implicitly_wait(10)
def loadWebsite(self, uri):
self.driver.get(uri)
cookies_accept_btn = self.driver.find_element_by_xpath('/html/body/div/div[3]/div[5]/button[2]')
cookies_accept_btn.click()
def main():
bot = trackerBot()
bot.loadWebsite("https://www.tori.fi")
return(0)
main()
Can someone advise what I'm missing? Many thanks in advance!