0

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

  • 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 '18 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. – Peter M. Feb 14 '18 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 Aggarwal Feb 19 '18 at 13:12
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, privacy policy and cookie policy

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