[英]Sorting a WebElement List to find specific Element (Selenium WebDriver/Java)
[英]How assign Value to Xpath to find element by WebDriver or WebElement in java code
這是我的Java 代碼
List<?> imageList =driver.findElementsByXPath("//*[@class='android.widget.ImageButton' and @index='0']");
我想將類和索引更改為隨機值。 我嘗試設置兩個變量並替換類和索引值,但沒有用。
List<?> imageList =driver.findElementsByXPath("\"//*"+"[@class="+"'"+Itemname+"'"+" "+"and"+" "+"@index="+"'"+Value+"'"+"]\"");
錯誤信息是
Exception in thread "main" org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters.
有什么辦法可以幫我解決這個問題嗎?? 非常感謝您的時間和幫助。
像這樣嘗試
String ItemName="android.widget.ImageButton";
String Value="0";
String str="//*[@class='"+ItemName+"' and @index='"+Value+"']"; //use this str in code
//or you can directly use like below
List imageList =driver.findElementsByXPath("//*[@class='"+ItemName+"' and @index='"+Value+"']");
謝謝,穆拉利
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.