我想自動使用硒的webdriver的Android網絡應用程序,我已經運行一個簡單的程序打開谷歌頁面和搜索項的元素有困難。找到具有名稱和ID的元素時,它可以完美運行。但是試圖用Xpath和Css查找元素似乎很困難。有誰知道如何在selenium android webdriver中使用xpath和css路徑嗎?下面是示例代碼中,我使用:找到使用XPath和CSS中硒的Android webdriver的測試
public class TestDriver extends TestCase
{
public static void testGoogle() throws Exception
{
AndroidDriver driver = new AndroidDriver();
driver.get("http://google.com");
WebElement element = driver.findElement(By.name("q"));
//WebElement element = driver.findElement(By.xpath("//*[@id='gbqfq']"));
//WebElement element = driver.findElement(By.cssSelector("#gbqfq"));
element.sendKeys("android driver");
element.submit();
System.out.println("Page title is: " + driver.getTitle());
//driver.quit();
}
}
感謝Ripon Al Wasim提供的解決方案,我正在尋求解決方案 – Rajeshwaran