英文:
Can't click a button in Selenium (Python), even though the element was identified correctly
问题
I am trying to click the Finish button on the following document URL:
https://app.pandadoc.com/p/99be757d50d745395babf924f529d9b7d207b7ec?
And while the finish_button.get_attribute('outerHTML') line outputs the correct answer to find the button (hence it's correctly identified), the program does not returns any errors and also doesn't actually click the button.
print(f"Requesting {document_URL}")
driver.get(document_URL)
print("Waiting for page to load...")
time.sleep(30)
document_detail_page = driver.current_url
print(f'Current page url: {document_detail_page}')
print("Accepting Cookies")
accept_cookies = driver.find_element(By.ID, 'onetrust-accept-btn-handler')
accept_cookies.click()
time.sleep(15)
print("Finding Finish Button to click")
finish_button = driver.find_element(By.XPATH, '//button[text()="Finish"]')
print(f"HTML of button: {finish_button.get_attribute('outerHTML')}")
英文:
I am trying to click the Finish button on the following document URL:
https://app.pandadoc.com/p/99be757d50d745395babf924f529d9b7d207b7ec?
And while the finish_button.get_attribute('outerHTML') line outputs the correct answer to find the button (hence it's correctly identified), the program does not returns any errors and also doesn't actually click the button.
print(f"Requesting {document_URL}")
driver.get(document_URL)
print("Waiting for page to load...")
time.sleep(30)
document_detail_page = driver.current_url
print(f'Current page url: {document_detail_page}')
print("Accepting Cookies")
accept_cookies = driver.find_element(By.ID, 'onetrust-accept-btn-handler')
accept_cookies.click()
time.sleep(15)
print("Finding Finish Button to click")
finish_button = driver.find_element(By.XPATH, '//button[text()="Finish"]')
print(f"HTML of button: {finish_button.get_attribute('outerHTML')}")`
I've tried the following 3 approaches, none of which worked:
finish_button.click()
ActionChains(driver).click(finish_button).perform()
webdriver.ActionChains(driver).move_to_element(finish_button).click(finish_button).perform()
`
EDIT: Someone seems to have clicked the link and hit the button manually (or figured out the solution but didn't post it here). The same goes for the now visible "Download" button that seems to have the same properties.
答案1
得分: 1
我只看到一个 "下载" 按钮。以下是使用 SeleniumBase 点击它并验证下载的Python脚本(在执行 "pip install seleniumbase" 并使用 "python" 运行之后):
from seleniumbase import SB
with SB(browser="chrome", headless=False) as sb:
sb.open("https://app.pandadoc.com/p/99be757d50d745395babf924f529d9b7d207b7ec")
sb.click('button[color="primary"]')
sb.assert_downloaded_file("NDA.pdf") # 在 ./downloaded_files/ 中搜索
sb.sleep(5)
英文:
All I see is a Download
button. Here's a Python script that clicks it with SeleniumBase (and verifies the download) after pip install seleniumbase
and running with python
:
from seleniumbase import SB
with SB(browser="chrome", headless=False) as sb:
sb.open("https://app.pandadoc.com/p/99be757d50d745395babf924f529d9b7d207b7ec")
sb.click('button[color="primary"]')
sb.assert_downloaded_file("NDA.pdf") # Searching ./downloaded_files/
sb.sleep(5)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论