I need to store the values from a list and then need to select a value from the list which matches the value of a variable declared.
I'm using cucumber framework and Java
I have already found the element from which the values needs to be stored.
I'm attaching the HTML tag image.
I'm not so acquainted with Java.
-
Can you give an example? What would contain a variable and what would you like to take from the list according to that variable value?– Alexey R.Feb 14, 2018 at 16:54
-
2You need to improve your Java skills. Problem has nothing to to do with webdriver, and you would not use webdriver to store values: webdriver is a library which java uses to automate the browser. IOW this is a java question, not a webdriver question.– Peter M. - stands for MonicaFeb 14, 2018 at 19:08
-
+1, Peter I observed the same thing in other multiple questions where people mix language level issues with automation framework/library.– Vishal AggarwalFeb 19, 2018 at 13:12
1 Answer
Try this,
WebElement ul= driver.findElement(By.xpath("//ul[@class='addressListItems']"));//xpath of ul
Thread.sleep(3000);
List<WebElement> allOptions= ul.findElements(By.tagName("li"));
for(WebElement selectLi: allOptions)
{
if(selectLi.getText().equals(data)) {
selectLi.click();
}
}
Learn List of WebElement concept