使用Selenium Java和Appium无法在Firefox Android应用程序中找到插件按钮

时间:2019-07-16 12:45:54

标签: selenium appium

Selenium无法在firefox android应用上找到插件按钮。我已经尝试了id和xpath定位器。

这是代码段:

// driver is an instance of AndroidDriver
driver.navigate().to("about:addons");
Thread.sleep(5000);

WebElement mainLayout = driver.findElementById("org.mozilla.firefox:id/main_layout");
System.out.println("#" + mainLayout.getText());

WebElement addonsList = driver.findElementById("addons-list");
System.out.println("@" + addonsList);

MobileElement randomUserAgent = (MobileElement) addonsList.findElement(By.xpath("//android.widget.Button[5]"));
System.out.println(randomUserAgent);

enter image description here

enter image description here

我能够打开插件页面,但是此后我得到以下错误(无法找到ID为“ addons-list”的元素):

org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. 

任何人都可以帮助我找到并点击加载项按钮。 谢谢

1 个答案:

答案 0 :(得分:0)

我宁愿以另一种方式在移动Firefox上更改用户代理:通过手动更改浏览器的首选项:

  1. 打开一个新标签,然后在地址栏中输入以下文本:

about:config

  1. 在搜索框中输入以下文本:

general.useragent.overridepreference

  1. 如果没有值general.useragent.overridepreference,请自行创建。右键单击about:config页面,然后在上下文菜单中转到New-> String。

更多详细信息here