1

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. enter image description here

3
  • 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
  • 2
    You 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. Feb 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. Feb 19, 2018 at 13:12

1 Answer 1

2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.