Selenium 3.0.1与IE11在Windows 10上找不到元素(在Windows 7上使用IE11正常工作)

时间:2017-03-01 21:38:43

标签: python selenium selenium-webdriver internet-explorer-11 selenium-iedriver

  • 操作系统:Windows 10
  • 浏览器:IE11
  • Selenium(Python)包:3.0.1
  • IEWebDriverServer.exe:3.1.0

我们正准备将自动化节点迁移到Windows 10,在我们的测试中,我们发现尽管我们的脚本在FF,IE和Chrome上的Win7上运行良好,但它们仅在Windows 10上因IE而失败(适用于FF和Chrome)。

当运行agianst IE时,浏览器实例化,webdriver能够看到浏览器(我尝试了一个简单的命令,如driver.back()返回上一页)。但是,我们无法获得任何find_element ...调用工作。无论是id,name,css,xpath等,脚本都会失败,说明找不到给定id / name / css / xpath的元素(无论我试图用什么方法来查找webelement)。

我见过有关安全更新的帖子,这些帖子打破了这一点并建议还原更新。这是一年前的事情,似乎随后的更新已经解决了这个问题。

我还阅读了有关确保所有区域中的保护模式相同,注册表值等的帖子。但这些建议都没有奏效。

以下是我正在使用的示例脚本(修改为在Chrome或Firefox中运行时)仅在IE11中不起作用:

mysql_query("DELETE FROM
 l2 WHERE
 data NOT IN ( 
     SELECT Top 10  data
     FROM l2
     ORDER BY data desc
)", $con);

运行此脚本的错误是:

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")

2 个答案:

答案 0 :(得分:0)

虽然我确定你现在不打扰,但我几天前记录了同样的问题而且我仍然被卡住了(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环境所以希望当我把它旋转时它应该正常工作(手指交叉)。

P.S。我不认为你的VM坏了!!

答案 1 :(得分:0)

每当我偶然发现'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 Scraping。我希望这会有所帮助,虽然目前我还没有Windows或IE来提前验证。

相关问题