我在使用Selenium WebDriver时遇到了问题。 我是Selenium WebDriver的初学者,所以请原谅我。 通过创建一个简单的webdriver测试,我已经按照一步一步的somme解释,但它仍然无法正常工作。 我可以说我已经在我的项目中添加了webdriver。
这似乎是因为我使用的是Firefox 3.5.19 .. 。那是什么原因? 这是我的代码:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
public class JobServe {
/**
* @param args
**/
public static void main(String[] args) {
// TODO Auto-generated method stub
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.type", 1);
profile.setPreference("network.proxy.http", "proxyfam");
profile.setPreference("network.proxy.http_port", 8080);
WebDriver driver = new FirefoxDriver(profile);
driver.get("http://www.jobserve.com.au/Homepage.aspx");
driver.findElement(By.xpath("html/body/form/div[4]/div[1]/div[12]/div[1]/div/div[1]/a[2]/span")).click();
}
}
这是错误日志:
Exception in thread "main" org.openqa.selenium.InvalidElementStateException: [Exception... "Component returned failure code: 0x80004003 (NS_ERROR_INVALID_POINTER) [nsINativeMouse.mouseMove]" nsresult: "0x80004003 (NS_ERROR_INVALID_POINTER)" location: "JS frame :: file:///C:/DOCUME~1/plegeard/LOCALS~1/Temp/anonymous1872429321029396376webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js :: anonymous :: line 9839" data: no]
Command duration or timeout: 62 milliseconds
Build info: version: '2.32.0', revision: '6c40c18', time: '2013-04-09 17:23:22'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0-OpenSCG-Build-24'
Session ID: e3d70b9d-8b0e-4dca-80e0-6989d0e62497
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, javascriptEnabled=true, acceptSslCerts=true, browserName=firefox, rotatable=false, locationContextEnabled=true, version=3.5.19, cssSelectorsEnabled=true, handlesAlerts=true, nativeEvents=true, webStorageEnabled=true, applicationCacheEnabled=true, takesScreenshot=true}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:187)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:268)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:79)
at JobServe.main(JobServe.java:22)
Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: [Exception... "Component returned failure code: 0x80004003 (NS_ERROR_INVALID_POINTER) [nsINativeMouse.mouseMove]" nsresult: "0x80004003 (NS_ERROR_INVALID_POINTER)" location: "JS frame :: file:///C:/DOCUME~1/plegeard/LOCALS~1/Temp/anonymous1872429321029396376webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js :: anonymous :: line 9839" data: no]
Build info: version: '2.32.0', revision: '6c40c18', time: '2013-04-09 17:23:22'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0-OpenSCG-Build-24'
Driver info: driver.version: unknown
at <anonymous class>.<anonymous method>(file:///C:/DOCUME~1/plegeard/LOCALS~1/Temp/anonymous1872429321029396376webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js:6891)
at <anonymous class>.<anonymous method>(file:///C:/DOCUME~1/plegeard/LOCALS~1/Temp/anonymous1872429321029396376webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js:9848)
at <anonymous class>.<anonymous method>(file:///C:/DOCUME~1/plegeard/LOCALS~1/Temp/anonymous1872429321029396376webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js:265)
at <anonymous class>.<anonymous method>(file:///C:/DOCUME~1/plegeard/LOCALS~1/Temp/anonymous1872429321029396376webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js:10421)
at <anonymous class>.<anonymous method>(file:///C:/DOCUME~1/plegeard/LOCALS~1/Temp/anonymous1872429321029396376webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js:10426)
at <anonymous class>.<anonymous method>(file:///C:/DOCUME~1/plegeard/LOCALS~1/Temp/anonymous1872429321029396376webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js:10366)
有没有人可以有任何想法?
提前致谢。
答案 0 :(得分:1)
保持通知。 我使用的是Firefox 3.5.19(由于工作限制)
通过将Selenium Webdriver从2.32降级到2.28,它现在正在运行......
THKS。
答案 1 :(得分:0)
尝试一些Implicit wait,然后点击试试这个
driver.get("http://www.jobserve.com.au/Homepage.aspx");
WebElement maybeClickable = driver.findElement(By.xpath("html/body/form/div[4]/div[1]/div[12]/div[1]/div/div[1]/a[2]/span"))
System.out.println(maybeClickable.isEnabled());
应打印出true
如果不是......那么该元素可能无法点击......