我们正在准备将我们的自动化节点迁移到Windows 10,在测试过程中,我们发现虽然我们的脚本在FF、IE和Chrome上运行良好,但是它们只在Windows 10上失败(对于FF和Chrome很好)。
在运行agianst时,浏览器实例化并能够看到浏览器(我尝试了一个简单的命令,如driver.back(),它返回到上一页)。然而,我们不能得到任何find_element.打电话来上班。无论是id、name、css、xpath等等,脚本都会失败,说明没有为给定的id/name/css/xpath找到任何元素(无论我试图使用什么方法来查找webelement)。
我看到了一些关于安全更新的帖子,这些更新破坏了这一点,并建议恢复更新。不过这是一年前的事了,后来的更新似乎已经解决了这个问题。
我还读过关于确保所有区域、注册表值等受保护模式相同的帖子。不过,这些建议都没有奏效。
下面是我使用的示例脚本(当修改为在Chrome或Firefox中运行时)仅在IE11中不起作用:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Ie()
driver.implicitly_wait(30)
driver.maximize_window()
# navigate to the application home page
driver.get("http://www.google.com")
# get the search textbox
search_field = driver.find_element_by_id("lst-ib")运行此脚本时出现的错误是:
selenium.common.exceptions.NoSuchElementException: Message: Unable to find element with id == lst-ib发布于 2017-03-08 03:53:43
虽然我确信你现在没有那么麻烦,但几天前我也记录了同样的问题,但我仍然卡住了(click here)。我已经把问题进一步缩小到安全问题上了。如果增加日志记录,您将看到以下行:
W 2017-03-06 17:27:41:539 Script.cpp(494) -2147024891 [Access is denied.]: Unable to execute code, call to IHTMLWindow2::execScript failed
W 2017-03-06 17:27:41:540 Script.cpp(180) Cannot create anonymous function
W 2017-03-06 17:27:41:540 ElementFinder.cpp(98) A JavaScript error was encountered executing the findElement atom. 我已经试过了所有的安全选项,但都没有用。我在本地得到了这个问题,而且还没有建立我的CI环境,所以希望当我把它旋转起来时,它应该能正常工作(手指祈祷)。
我不认为你的VM坏了!!
发布于 2017-03-08 04:33:40
每当我偶然发现一个'NoSuchElementException‘(虽然不是在Windows或IE上),这总是有效的:
加上这些进口品:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By然后定位元素:
search_field = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, """//*[@id="lst-ib"]""")))
search_field.send_keys('Example')这归功于使用Python进行Web抓取。我希望这有帮助,虽然目前我没有窗口或IE来验证这一点。
https://stackoverflow.com/questions/42542571
复制相似问题