I try to develop a python script based on Selenium to manipulate a website. Here is the website:
https://www.heatpumpkeymark.com/en/?type=109126&tx_pskeymark_frontend%5Bholder%5D=2482&tx_pskeymark_frontend%5Baction%5D=certificateHolder&tx_pskeymark_frontend%5Bcontroller%5D=Frontend&cHash=1f82e53f3d95d0b9ebfe0c7bb0cdfeb2
and I want to find and click on the button “Download reports for all subtypes”. I succeed to do it in other websites but not in that one.
My following scripts doesn’t work.
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
webdriver_path = r'D:MyWorkdriverchromedriver.exe'
service = Service(webdriver_path)
chrome_options = Options()
url = "https://www.heatpumpkeymark.com/en/?type=109126&tx_pskeymark_frontend%5Bholder%5D=2482&tx_pskeymark_frontend%5Baction%5D=certificateHolder&tx_pskeymark_frontend%5Bcontroller%5D=Frontend&cHash=1f82e53f3d95d0b9ebfe0c7bb0cdfeb2"
driver = webdriver.Chrome(service=service, options=chrome_options)
driver.get(url)
time.sleep(3)
wait = WebDriverWait(driver, 5)
class_name = 'btn btn-primary'
text = 'Download reports for all subtypes'
try:
# button = wait.until(EC.element_to_be_clickable((By.XPATH, f'//button[class()="{class_name}"]')))
button = wait.until(EC.element_to_be_clickable((By.XPATH, f'//button[text()="{text}"]')))
if button:
print('Button found')
else:
print('Button not found')
finally:
driver.quit()```
When running the above script, the error is on the line "button = ...", as following:
TimeoutException Traceback (most recent call last)
Cell In[9], line 29
25 text = 'Download reports for all subtypes'
27 try:
28 # button = wait.until(EC.element_to_be_clickable((By.XPATH, f'//button[class()="{class_name}"]')))
---> 29 button = wait.until(EC.element_to_be_clickable((By.XPATH, f'//button[text()="{text}"]')))
31 if button:
32 print('Button found')
File c:UsersctranAppDataLocalProgramsPythonPython312Libsite-packagesseleniumwebdriversupportwait.py:105, in WebDriverWait.until(self, method, message)
103 if time.monotonic() > end_time:
104 break
--> 105 raise TimeoutException(message, screen, stacktrace)
TimeoutException: Message:
Stacktrace:
GetHandleVerifier [0x00007FF6268F22C2+60002]
(No symbol) [0x00007FF62686CA59]
(No symbol) [0x00007FF626727EDA]
(No symbol) [0x00007FF6267776E6]
(No symbol) [0x00007FF6267777AC]
...
Have you any idea to solve the problem? Thank you for your help.
TTown is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.