I am new to Selenium and I try to find what's wrong with my code. I think the problem is not with slow loading of page(it is very slow), but when the code is reaching print('I am wating')
program is waiting 30 seconds and after that I am having the error selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element:
. When it reaches this moment, there is no loading of the page or sth like that, it is just printing this information and after 30 seconds it gives these error. Code of my program is below.
from selenium import webdriver
from selenium.webdriver.common.by import By
import os
import typing
import types
class BrowserOperator(webdriver.Chrome):
def __init__(self, page_url, teardown: bool = False):
self._teardown = teardown
self._pageUrl = page_url
options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging'])
super(BrowserOperator, self).__init__(options=options)
self.implicitly_wait(30)
self.maximize_window()
def __exit__(self, exc_type: typing.Optional[typing.Type[BaseException]], exc: typing.Optional[BaseException], traceback: typing.Optional[types.TracebackType]):
print(self._teardown)
if self._teardown:
print(self._teardown)
self.quit()
def load_first_page(self):
self.get(self._pageUrl)
def check_address_correctness(self):
if self.current_url != self._pageUrl:
return self.load_first_page()
def accept_cookies(self):
print('I am wating')
cookie_button = self.find_element(
By.XPATH, '/html/body/div[1]/div[2]/div[2]/div/div[3]/button[2]')
print(cookie_button)
# cookie_button.click()