[英]facing an issue while executing Xpath with Index code in APPIUM
Appium日志補丁:
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":32,"value":"javax.xml.transform.TransformerException: Extra illegal tokens: ')', '[', '2', ']'"}
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [MJSONWP] Matched JSONWP error code 32 to InvalidSelectorError
[debug] [W3C (065be1bf)] Encountered internal error running command: InvalidSelectorError: javax.xml.transform.TransformerException: Extra illegal tokens: ')', '[', '2', ']'
Eclipse代碼:
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//to click on specific object/position on a screen
driver.findElementByXPath("//android.widget.TextView[@text='Preference']").click();
driver.findElementByXPath("//android.widget.TextView[@text='3. Preference dependencies']").click();
//finding element by ID
driver.findElementById("android:id/checkbox").click();
//
driver.findElementByXPath("//android.widget.RelativeLayout)[2]").click();
driver.findElementByClassName("//android.widget.EditText").sendKeys("Hello");
driver.findElementsByClassName("android.widget.Button").get(1).click();
直到第三行,代碼都可以正常工作,但是在那之后,它停止了,並且沒有轉到下一行代碼,並在Appium中顯示了上述錯誤。
行driver.findElementByXPath("//android.widget.RelativeLayout)[2]").click();
缺少括號driver.findElementByXPath("//android.widget.RelativeLayout)[2]").click();
如果要使用xpath轉到第二個索引,則需要在啟動xpath之前添加括號,例如:
driver.findElementByXPath("(//android.widget.RelativeLayout)[2]").click();
另外,在下一行中,您使用的是className,如果在標識元素時使用了id
或className
類的任何標記,則//
不使用,因此您需要將其更改為:
driver.findElementByClassName("android.widget.EditText").sendKeys("Hello");
否則將拋出NoSuchElementException
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.