在尝试获取xpath的所有方法后无法单击

时间:2016-05-17 11:54:11

标签: javascript android appium

我无法点击并尝试获取x-path的所有方法,即使我的脚本正在通过,仍然没有点击我的设备(真正的Android手机)!使用appium和selenium。 是因为两个跨度(见下图)?我想点击MINT_1150 !!! 有人可以帮忙吗?

enter image description here

UIAutomator图片同样在这里:

enter image description here

2 个答案:

答案 0 :(得分:0)

我相信你指的是错误的元素。仍然记下这两件事:

  1. 确保您将上下文切换到WEBVIEW,以便在此屏幕上处理任何自动案例,因为它是应用程序内的Web视图。

    Set<String> contextNames = driver.getContextHandles();
    for (String contextName : contextNames) {
        System.out.println(contextName);
        if (contextName.contains("WEBVIEW")){
            driver.context(contextName);
        }
    }
    
  2. IF 第1点被处理,尝试并以

    方式访问该元素
    WebElement yourElement = findElement(By.class("<classname>")); //to access the element
    yourElement.click(); //click on that element
    
  3. 注意:还要确保应用内的yourElement 可点击

    编辑:在您的情况下,您可以按如下方式访问该元素:

    WebElement yourElement = findElement(By.id("ext-component-4")); //to access the element
    yourElement.click(); //perform click
    

    Edit2

    Actions action=new Actions(driver);
    action.moveToElement(tElement).moveByOffset(0, 0).perform();
    Thread.sleep(10000);
    action.click().build().perform(); // build the action and perform it as well
    

答案 1 :(得分:0)

如果没有用完整的HTML发布它,我们将无法验证xpath。

但是对于这种情况,使用css选择器来选择特定元素而不是XPath会很简单。以下选择器应选择您要查找的元素。

  

&#39; #ext-element-39 .archive-name&#39;

我不知道appium但是使用C#selenium我们可以像下面这样做

Driver.FindElement(By.CssSelector('#ext-element-39 .archive-name'))

在appium中也应该有类似的方法。

还有一个选项是您可以使用谷歌浏览器来获取正确的xpath。右键单击节点,然后选择“复制Xpath”

enter image description here

希望这会有所帮助!!