TA的每日心情 | 衰 2024-5-20 21:29 |
---|
签到天数: 996 天 连续签到: 1 天 [LV.10]测试总司令
|
package com.example.tests;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import com.sun.org.apache.xerces.internal.impl.xpath.XPath;
public class Demo {
public static void main(String[] args){
System.setProperty("webdriver.gecko.driver","C:\\Program Files (x86)\\Mozilla Firefox\\webdriver\\geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.get("http://www.baidu.com");
System.out.println("Page title is :"+driver.getTitle());
//WebElement username=driver.findElement(By.xpath("//form/div[1]/input[@id='lgn_txt_username']"));
WebElement Text=driver.findElement(By.xpath("html/body/div[2]/div[1]/div/div[1]/div/form/span[1]/input"));
Text.clear();
Text.sendKeys("abc");
//username.sendKeys("admin");
}
}
只想在百度输入框内 输入abc但是Eclipse运行此断代码就报错。
只能打开百度页面不能执行输入操作。
下面试Eclipse中运行Console中的信息
1497512421381 geckodriver INFO Listening on 127.0.0.1:30863
六月 15, 2017 3:40:21 下午 org.openqa.selenium.remote.ProtocolHandshake createSession
信息: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
1497512421978 mozprofile::profile INFO Using profile path C:\Users\ADMINI~1\AppData\Local\Temp\rust_mozprofile.PKQFmN5A8CRE
1497512421982 geckodriver::marionette INFO Starting browser C:\Program Files (x86)\Mozilla Firefox\firefox.exe
1497512421990 geckodriver::marionette INFO Connecting to Marionette on localhost:63668
1497512424910 Marionette INFO Listening on port 63668
[GPU 10336] WARNING: pipe error: 109: file c:/builds/moz2_slave/m-rel-w32-00000000000000000000/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
六月 15, 2017 3:40:25 下午 org.openqa.selenium.remote.ProtocolHandshake createSession
信息: Detected dialect: W3C
Page title is :百度一下,?就知道
Exception in thread "main" org.openqa.selenium.InvalidArgumentException: Expected [object Undefined] undefined to be a string
Build info: version: 'unknown', revision: '1969d75', time: '2016-10-18 09:43:45 -0700'
System info: host: '13K2G_wangchunpeng', ip: '10.241.36.187', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_131'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{moz:profile=C:\Users\ADMINI~1\AppData\Local\Temp\rust_mozprofile.PKQFmN5A8CRE, rotatable=false, timeouts={implicit=0, pageLoad=300000, script=30000}, pageLoadStrategy=normal, platform=ANY, specificationLevel=0, moz:accessibilityChecks=false, acceptInsecureCerts=false, browserVersion=53.0.3, platformVersion=10.0, moz:processID=520, browserName=firefox, platformName=windows_nt}]
Session ID: 24f372f7-6351-4d8b-9c2f-91e082353358
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.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:127)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:93)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:42)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:163)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:274)
at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:98)
at com.example.tests.Demo.main(Demo.java:19)
|
|