我試圖在使用Appium和AndriodDriver的google.com頁面上找到WebElement。每次我嘗試運行代碼時,Selenium都拋出異常。 客戶:Appium:測試無法自動化基於Web的應用程序
@Test
public void mobWebAppTest() throws Exception{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("automationName", "Appium");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("platformVersion", "4.3");
capabilities.setCapability("deviceName", "4df12fbe651cafd3");
capabilities.setCapability("appPackage", "com.android.browser");
capabilities.setCapability("appActivity", "BrowserActivity");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
AndroidDriver<WebElement> driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("https://www.google.com/");
driver.findElement(By.xpath("//input[@name='q']")); // the error is thrown here
driver.quit();
}
異常日誌:
org.openqa.selenium.NoSuchElementException: An element could not be located on
the page using the given search parameters. (WARNING: The server did not
provide any stacktrace information)
Command duration or timeout: 30.31 seconds
For documentation on this error, please visit:
http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.53.1', revision:
'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09'
System info: host: '*******', ip: '*******', os.name: 'Mac OS X', os.arch:
'x86_64', os.version: '10.10.5', java.version: '1.8.0_11'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{appPackage=com.android.browser, deviceScreenSize=720x1280,
networkConnectionEnabled=true, warnings={}, databaseEnabled=false,
deviceName=4df12fbe651cafd3, platform=LINUX, deviceUDID=4df12fbe651cafd3,
appActivity=BrowserActivity, desired={appPackage=com.android.browser,
appActivity=BrowserActivity, platformVersion=4.3, automationName=Appium,
browserName=Android, platformName=Android, deviceName=4df12fbe651cafd3},
platformVersion=4.3, webStorageEnabled=false, locationContextEnabled=false,
automationName=Appium, takesScreenshot=true, browserName=Android,
javascriptEnabled=true, deviceModel=GT-I9300, platformName=Android,
deviceManufacturer=samsung}]
Session ID: c68c1f7d-0e6e-481a-a335-23ede1de7de9
*** Element info: {Using=xpath, value=//input[@name='q']}
at ...
而且,當我試圖讓網頁的源代碼,我找回了XML的(如在用戶界面的Automator)整個屏幕,而不是谷歌網頁的HTML。這是否是例外的原因?
謝謝你。
除上述帖子外。 依賴如下: selenium-server.2.52.1; java-client:4.1.1 – Vlad