如何在自动化iPhone应用程序时使用HTML xpath
Im使用Appuim+Selenium Webdriver。 我的应用程序是在Sencha框架中构建的,因此使用Appium Inspector无法找到某些元素。 所以我尝试使用HTMLXPath,但它给出了“元素未找到异常” 我正在粘贴下面的代码:如何在自动化iPhone应用程序时使用HTML xpath,xpath,selenium-webdriver,ios-ui-automation,appium-ios,Xpath,Selenium Webdriver,Ios Ui Automation,Appium Ios,Im使用Appuim+Selenium Webdriver。 我的应用程序是在Sencha框架中构建的,因此使用Appium Inspector无法找到某些元素。 所以我尝试使用HTMLXPath,但它给出了“元素未找到异常” 我正在粘贴下面的代码: wd.findElement(By.xpath("//*[@id='DashBoardView_cityInsightsItemId']/div/div/div[2]/div[1]/div")).click(); <div class="x
wd.findElement(By.xpath("//*[@id='DashBoardView_cityInsightsItemId']/div/div/div[2]/div[1]/div")).click();
<div class="x-container dashboard_item_cls x-layout-box-item x-stretched" id="DashBoardView_cityInsightsItemId" style=""><div class="x-inner x-vertical x-align-center x-pack-center x-layout-box" id="ext-element-125"><div class="x-img x-img-image x-paint-monitored x-size-monitored dashboard_icon_cls cityInsights_icon_cls x-img-background x-layout-box-item x-stretched" id="ext-image-3"><div class="x-paint-monitor cssanimation"></div><div class="x-size-monitors overflowchanged"><div class="expand"><div style="width: 68.1875px; height: 68.1875px;"></div></div><div class="shrink"><div style="width:
67.1875px; height: 67.1875px;"></div></div></div></div></div></div>
控制台中的错误为:
wd.findElement(By.xpath("//*[@id='DashBoardView_cityInsightsItemId']/div/div/div[2]/div[1]/div")).click();
<div class="x-container dashboard_item_cls x-layout-box-item x-stretched" id="DashBoardView_cityInsightsItemId" style=""><div class="x-inner x-vertical x-align-center x-pack-center x-layout-box" id="ext-element-125"><div class="x-img x-img-image x-paint-monitored x-size-monitored dashboard_icon_cls cityInsights_icon_cls x-img-background x-layout-box-item x-stretched" id="ext-image-3"><div class="x-paint-monitor cssanimation"></div><div class="x-size-monitors overflowchanged"><div class="expand"><div style="width: 68.1875px; height: 68.1875px;"></div></div><div class="shrink"><div style="width:
67.1875px; height: 67.1875px;"></div></div></div></div></div></div>
*exceptionorg.openqa.selenium.NoSuchElementException:使用给定的搜索参数在页面上找不到元素。
(警告:服务器未提供任何stacktrace信息)
命令持续时间或超时:关于此命令的文档记录为1.52秒
错误,请访问:
构建信息:
版本:“2.51.0”,修订版:“1af067d”,时间:“2016-02-05 19:15:17”
os.name:'Mac os X',os.arch:'x86_64',os.version:'10.10.5',
java.version:'1.8.0_73'驱动程序信息:
org.openqa.selenium.remote.RemoteWebDriver功能[]会话
ID:4c466315-67c5-409e-9ffc-1f0d26c134c4
元素信息:{Using=xpath,value=/[@id='DashBoardView\u cityInsightsItemId']/div/div/div[2]/div[1]/div}*
HTML代码:
wd.findElement(By.xpath("//*[@id='DashBoardView_cityInsightsItemId']/div/div/div[2]/div[1]/div")).click();
<div class="x-container dashboard_item_cls x-layout-box-item x-stretched" id="DashBoardView_cityInsightsItemId" style=""><div class="x-inner x-vertical x-align-center x-pack-center x-layout-box" id="ext-element-125"><div class="x-img x-img-image x-paint-monitored x-size-monitored dashboard_icon_cls cityInsights_icon_cls x-img-background x-layout-box-item x-stretched" id="ext-image-3"><div class="x-paint-monitor cssanimation"></div><div class="x-size-monitors overflowchanged"><div class="expand"><div style="width: 68.1875px; height: 68.1875px;"></div></div><div class="shrink"><div style="width:
67.1875px; height: 67.1875px;"></div></div></div></div></div></div>
我要查找此元素:
为什么会出现此错误以及如何解决此错误?您是否注意到您提供的xpath在开始时有“/*[@id=”,但错误消息指出“/[@id=…”?您也找不到更具体的xpath,例如“//div[@id=”DashBoardView\u cityInsightsItemId']//div[@class=“shrink”]/div”实际上是***元素信息:{Using=xpath,value=//*[@id='DashBoardView\u cityInsightsItemId']/div/div/div[2]/div[1]/div}是一条消息,我不知道为什么Sencha框架类名中会出现no*,id是动态创建的。这就是为什么我只使用'div'