我在Windows XP上使用最新的Selenium代码,2.25 IEDriver 2.25.2 32位,IE 8 32位。使用下面的简单代码清单,我从未进入“Found element !!”如果我使用InternetExplorerDriver,则行。它打开页面,读取页面标题但在findElement调用上失败。如果我交换到FirefoxDriver它的工作原理。我已经能够通过集线器将IE 9 64位工作在远程PC上(取消注释前两行并注释掉两个WebDriver行)。
不明白为什么IE 32位失败了。
===========================================
package com.company.test;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class App
{
public static void main( String[] args ) throws InterruptedException, MalformedURLException
{
// Grid driver
// DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
// WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
// Local driver
// WebDriver driver = new FirefoxDriver();
WebDriver driver = new InternetExplorerDriver();
try {
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("http://seleniumhq.org/");
String pageTitle = driver.getTitle();
System.out.println("pageTitle=" + pageTitle);
driver.findElement(By.id("q")).clear();
System.out.println("Found element!!");
driver.findElement(By.id("q")).sendKeys("test");
driver.findElement(By.id("submit")).click();
} finally {
driver.quit();
}
System.out.println("Done");
}
}
=============================================== =============
我能够让IEDriver生成TRACE日志以下是感兴趣的片段:
T 2012-08-09 16:04:09:516 IECommandExecutor.cpp(604) Entering IECommandExecutor::LocateElement
T 2012-08-09 16:04:09:516 IECommandExecutor.cpp(587) Entering IECommandExecutor::GetElementFindMethod
T 2012-08-09 16:04:09:516 ElementFinder.cpp(33) Entering ElmentFinder::FindElement
T 2012-08-09 16:04:09:516 IECommandExecutor.cpp(439) Entering IECommandExecutor::GetCurrentBrowser
T 2012-08-09 16:04:09:516 IECommandExecutor.cpp(445) Entering IECommandExecutor::GetManagedBrowser
T 2012-08-09 16:04:09:516 ElementFinder.cpp(468) Entering ElementFinder::SanitizeCriteria
T 2012-08-09 16:04:09:516 ElementFinder.cpp(479) Entering ElementFinder::ReplaceAllSubstrings
T 2012-08-09 16:04:09:516 ElementFinder.cpp(479) Entering ElementFinder::ReplaceAllSubstrings
T 2012-08-09 16:04:09:516 Browser.cpp(91) Entering Browser::GetDocument
I 2012-08-09 16:04:09:516 Browser.cpp(95) No child frame focus. Focus is on top-level frame
T 2012-08-09 16:04:09:516 IECommandExecutor.cpp(187) Entering IECommandExecutor::OnGetResponseLength
T 2012-08-09 16:04:09:532 IECommandExecutor.cpp(187) Entering IECommandExecutor::OnGetResponseLength
T 2012-08-09 16:04:09:532 Browser.cpp(451) Entering Browser::GetDocumentFromWindow
T 2012-08-09 16:04:09:532 Script.cpp(40) Entering Script::Initialize
T 2012-08-09 16:04:09:532 Script.cpp(210) Entering Script::Execute
T 2012-08-09 16:04:09:532 Script.cpp(577) Entering Script::CreateAnonymousFunction
T 2012-08-09 16:04:09:547 IECommandExecutor.cpp(187) Entering IECommandExecutor::OnGetResponseLength
W 2012-08-09 16:04:09:547 Script.cpp(594) -2147024891 [Access is denied.]: Unable to execute code, call to IHTMLWindow2::execScript failed
W 2012-08-09 16:04:09:547 Script.cpp(221) Cannot create anonymous function
W 2012-08-09 16:04:09:547 ElementFinder.cpp(86) Unable to create criteria object for mechanism 00FBA030 and criteria00FB9FB0
我认为问题在于上面红色突出显示的部分,但我不知道如何解决这个问题。有人有什么想法吗?
答案 0 :(得分:0)
检查浏览器安全设置,确保已启用Active Scripting。要在IE9中启用,请执行以下操作: 1.单击“工具”图标。 (工具图标位于IE9的右上角,或者工具也可以在菜单栏上找到“工具”)。 2.然后点击 - > Internet选项“ - >安全选项卡 - >自定义级别按钮 - >滚动到底部附近的”脚本“部分,然后在”活动脚本“下选择启用。 3.单击“确定”。