|
package TestPackage;
import org.openqa.selenium.WebDriver.*;
import org.openqa.selenium.firefox.*;
import org.openqa.selenium.*;
public class Test2
{
/**
* @param args
* @throws InterruptedException
*/
public static void main(String[] args) throws InterruptedException
{
WebDriver driver=new FirefoxDriver();
Navigation navigation = driver.navigate();
navigation.to("http://www.baidu.com");
WebElement BaiduTextbox = driver.findElement(By.id("kw"));
BaiduTextbox.sendKeys("Hello");
driver.findElement(By.id("su")).click();
driver.findElement(By.xpath(".//*[@id='2']/h3/a/text()"));
}
}
报错:
Exception in thread "main" org.openqa.selenium.InvalidSelectorException: The given selector .//*[@id='2']/h3/a/text() is either invalid or does not result in a WebElement. The following error occurred:
InvalidSelectorError: The result of the xpath expression ".//*[@id='2']/h3/a/text()" is: [object Text]. It should be an element.
Command duration or timeout: 31 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/invalid_selector_exception.html
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:55:52'
System info: host: 'SHNDTPDL0883', ip: '10.225.117.12', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_55'
*** Element info: {Using=xpath, value=.//*[@id='2']/h3/a/text()}
Session ID: f92e4f2b-43be-4fba-abfb-6ec3d6bea5f5
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=WINDOWS, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, nativeEvents=false, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=43.0.3}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:647)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:353)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:490)
at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:345)
at TestPackage.Test2.main(Test2.java:33)
Caused by: org.openqa.selenium.InvalidSelectorException: The given selector .//*[@id='2']/h3/a/text() is either invalid or does not result in a WebElement. The following error occurred:
InvalidSelectorError: The result of the xpath expression ".//*[@id='2']/h3/a/text()" is: [object Text]. It should be an element.
For documentation on this error, please visit: http://seleniumhq.org/exceptions/invalid_selector_exception.html
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:55:52'
System info: host: 'SHNDTPDL0883', ip: '10.225.117.12', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_55'
Driver info: driver.version: unknown
at <anonymous class>.FirefoxDriver.annotateInvalidSelectorError_(file:///C:/Users/275873/AppData/Local/Temp/anonymous3656865153537910253webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js:10633)
at <anonymous class>.FirefoxDriver.prototype.findElementInternal_(file:///C:/Users/275873/AppData/Local/Temp/anonymous3656865153537910253webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js:10664)
at <anonymous class>.FirefoxDriver.prototype.findElement(file:///C:/Users/275873/AppData/Local/Temp/anonymous3656865153537910253webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js:10668)
at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///C:/Users/275873/AppData/Local/Temp/anonymous3656865153537910253webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12534)
at <anonymous class>.DelayedCommand.prototype.executeInternal_(file:///C:/Users/275873/AppData/Local/Temp/anonymous3656865153537910253webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12539)
at <anonymous class>.DelayedCommand.prototype.execute/<(file:///C:/Users/275873/AppData/Local/Temp/anonymous3656865153537910253webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12481)
感觉上好像是要点的URL没找到。。。求大神帮忙-。-
|
|