How to click on particular element in a list using selenium webdriver?

后端 未结 1 524
灰色年华
灰色年华 2021-01-28 00:46
  1. I have a name which is coming from excel sheet
  2. List of elements, having this particular name and i need to click on this element Here is my code:

    
    
            
相关标签:
1条回答
  • 2021-01-28 00:55

    Here it goes: Assuming your myElements will be as below:

    List<WebElement> myElements =driver.findElements(By.cssSelector("li[class*='rlbItem']"));
    
    for(WebElement li : myElements) 
    {
         System.out.println(li.getText());
         System.out.println();
    
         for (int i=0; i<Name.length(); i++)
         {
            if(li.getText().equalsIgnoreCase(Name[i]))
            {
                //Clicks on the matched webelement    
                li.click();
            }
          }
    }
    
    0 讨论(0)
提交回复
热议问题