通过Python使用find_element时,硒找不到元素 - python

不断收到unable to locate element错误消息。

xpath的第一个find元素很好,但是第二个给我带来了困难。

这是我的代码:

import XLUtils
from selenium import webdriver

driver=webdriver.Chrome(executable_path="C:\Chrome_Driver\Chromedriver.exe")
driver.get("https://www.canada.ca/en/revenue-agency/services/e-services/e-services-businesses/payroll-deductions-online-calculator.html")

driver.find_element_by_xpath('/html/body/main/div[1]/div[7]/p/a[1]').click()
driver.find_element_by_xpath('//*[@id="welcome_button_next"]').click()

参考方案

您需要稍等片刻,以显示Next按钮。

from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait

wait = WebDriverWait(driver, 10)

e = wait.until(
    EC.presence_of_element_located((By.XPATH, '//*[@id="welcome_button_next"]'))
    )
e.click()

Python sqlite3数据库已锁定 - python

我在Windows上使用Python 3和sqlite3。我正在开发一个使用数据库存储联系人的小型应用程序。我注意到,如果应用程序被强制关闭(通过错误或通过任务管理器结束),则会收到sqlite3错误(sqlite3.OperationalError:数据库已锁定)。我想这是因为在应用程序关闭之前,我没有正确关闭数据库连接。我已经试过了: connectio…

如何使用Selenium和Python启动基于Chromium的Vivaldi浏览器会话 - python

我正在尝试将vivaldi browser与Selenium一起使用。这是一款与Chrome浏览器非常相似的Chrome浏览器。我有Selenium与Firefox(geckodriver)和Google Chrome(chromedriver)一起工作,但是我似乎找不到Vivaldi的方法。任何帮助,将不胜感激。 python大神给出的解决方案 如果默认情…

硒独立服务器日志级别 - python

长话短说:我正在尝试将日志级别更改为Selenium独立服务器上的WARNING。我在CentOS 6.7上运行2.48.2。我在服务器端尝试过,即在启动服务器时添加了-Dselenium.LOGGER.level=WARNING-不起作用。然后,我尝试使用默认级别作为警告的自定义属性文件-Djava.util.logging.config.file=/op…

Python pytz时区函数返回的时区为9分钟 - python

由于某些原因,我无法从以下代码中找出原因:>>> from pytz import timezone >>> timezone('America/Chicago') 我得到:<DstTzInfo 'America/Chicago' LMT-1 day, 18:09:00 STD…

用大写字母拆分字符串,但忽略AAA Python Regex - python

我的正则表达式:vendor = "MyNameIsJoe. I'mWorkerInAAAinc." ven = re.split(r'(?<=[a-z])[A-Z]|[A-Z](?=[a-z])', vendor) 以大写字母分割字符串,例如:'我的名字是乔。 I'mWorkerInAAAinc”变成…