在硒中获取“对象不支持属性或方法“评估””| IE

问题描述 投票:0回答:1

我正在 IE(Internet Explorer)浏览器上自动化 Web 应用程序。

当我在页面加载后尝试查找页面上的任何元素时,出现以下错误。

selenium.common.exceptions.InvalidSelectorException: Message: Unable to locate an element with the xpath expression //div[@id='index_logo']/following-sibling::div/form because of the following error:
TypeError: Object doesn't support property or method 'evaluate';

代码

#xpaths
cpDvForm = "//div[@id='index_logo']/following-sibling::div/form"
cpDvUser = "//input[@id='username']"
cpDvPass = "//input[@id='password']"
cpDvLanRadio = "//input[@id='net_lan']"
cpDvLogin = "//a[@onclick='login()']"
#code
options= webdriver.IeOptions()
d = webdriver.Ie(options=options)
d.get(url)
#time.sleep(10)
#WebDriverWait(d,10).until(EC.element_to_be_clickable(d.find_element(By.XPATH,cpDvUser)))
form = d.find_element(By.XPATH,cpDvForm)
form.find_element(By.XPATH,cpDvUser).clear()
form.find_element(By.XPATH,cpDvUser).send_keys('user')
form.find_element(By.XPATH,cpDvPass).send_keys('pass')
form.find_element(By.XPATH,cpDvLanRadio).click()
form.find_element(By.XPATH,cpDvLogin).click()

我也尝试过引发 Webdriver 等待和睡眠等待,以确保页面加载。 我检查了 Iframe 和 Shadow dom。都没有。

如上所述,当我们在页面加载后尝试搜索任何元素时,就会发生错误。 感谢所有建议和解决方案!!

附加说明/信息:

  • 我需要使用IE浏览器
  • 硒4.18.0
  • Python 3.12

如果需要更多信息,请告诉我,我们将相应添加。干杯!

selenium-webdriver xpath internet-explorer internet-explorer-11
1个回答
0
投票

@JeffC 使用 ID 选择器突出显示

By.ID,'theId'
适用于此。 继续使用 ID 选择器。

即使 XPath 是正确的,但由于某些其他原因,它会抛出错误。

© www.soinside.com 2019 - 2024. All rights reserved.