0

I'm trying to open this webpage

https://albo-on-line.comune.verona.it/web/servizi/albo-pretorio

with this code:

# selenium 4
from selenium import webdriver
from selenium.webdriver.firefox.service import Service as FirefoxService
from selenium.webdriver.firefox.webdriver import WebDriver
from webdriver_manager.firefox import GeckoDriverManager

driver: WebDriver = webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install()))

url = "https://albo-on-line.comune.verona.it/web/servizi/albo-pretorio"

driver.get(url)
driver.implicitly_wait(10)

cookies = driver.find_element(By.xpath('//*[@id="cookie-privacy-close"]')).click()

determinazioni = driver.findElement(By.xpath('//*[@id="_menucontroller_WAR_maggiolialbopretorioportlet_MenuItem9"]')).click()

but no success

can you help me ?

thx

1 Answer 1

0

There are several thing here to improve:

  1. Your syntax is wrong.
    Instead of driver.find_element(By.xpath('//*[@id="cookie-privacy-close"]')) it should be driver.find_element(By.XPATH, '//*[@id="cookie-privacy-close"]')
  2. You should use WebDriverWait expected_conditions explicit waits, not implicitly_wait
  3. Since you locating these elements by their ID it's better to locate these elements by ID, not by XPath.

The following code works:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

options = Options()
options.add_argument("start-maximized")

webdriver_service = Service('C:\webdrivers\chromedriver.exe')
driver = webdriver.Chrome(options=options, service=webdriver_service)
wait = WebDriverWait(driver, 30)

url = "https://albo-on-line.comune.verona.it/web/servizi/albo-pretorio"
driver.get(url)

wait.until(EC.element_to_be_clickable((By.ID, 'cookie-privacy-close'))).click()
wait.until(EC.element_to_be_clickable((By.ID, '_menucontroller_WAR_maggiolialbopretorioportlet_MenuItem9'))).click()

The result is:

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

Hi thx for suggestion I've used your code it works but the webpage after open it immediately close
ok sorry I'm new and I'm trying to learn
I understand. This is why I gave you the link above to make you learn some basic roles of this forum. Actually not just this forum...

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.