How can I loop through list of WebElements and select one WebElement with a condition?
Tag : java , By : Ernie Thomason
Date : March 29 2020, 07:55 AM
around this issue I am using Selenium WebDriver with Java. I am trying to create a method that loops through a list of WebElements to return the first WebElement that contains the text "Ooga Booga", or return null if there are no elements in the list that contains this text. , Use findElement-S method as shown below. for (WebElement element : elements) {
List<WebElement> mightHaveSomeDiv = element.findElements(By.cssSelector("someDiv"));
if (mightHaveSomeDiv.size() > 0) {
//Can iterate the list if you expect more than one div of type someDiv.
String myText = mightHaveSomeDiv.get(0).getText();
if (myText.contains("Ooga Booga")) {
return element;
}
}
}
|
Difference WebElements Vs WebElement in selenium
Tag : java , By : ganok_tor
Date : March 29 2020, 07:55 AM
like below fixes the issue I am fetching date webelements from facebook and I am looping it by using the below code. , You will get list of Elements in return of List<WebElement> days = driver.findElements(By.xpath("//select[@id='day']"));
|
How to find a webelement that has 'checked' attribute in list of child WebElements through Selenium using Katalon Studio
Date : March 29 2020, 07:55 AM
wish of those help I was able to fix this by changing (".//*") to (".//*[@checked='checked']") parentWebElement.findElement(By.xpath(".//*[@checked='checked']")
public TestObject getCheckedTestObjectFromParent(String parentID){
WebDriver driver = DriverFactory.getWebDriver()
WebElement parentWebElement = driver.findElement(By.id(parentID))
//there is only 1 checked child at a time, so there is no need for a list
WebElement checkedChild = parentWebElement.findElement(By.xpath(".//*[@checked='checked']"))
//convert the WebElement to a TestObject and return
return getTestObjectFromWebElement(checkedChild)
}
|
Multiple WebElements from a list of any size using for loop
Tag : java , By : Sinisa Ruzin
Date : March 29 2020, 07:55 AM
help you fix your problem I am trying to grab specific web elements from a list using xpath that is not a fixed length. , puts those elements into a list for later use List<WebElement> nodelist = driver.findElements(By.xpath("//*[starts-with(@id,'node-')]"));
for (int i = 0; i < nodelist.size(); i++) {
WebElement node = driver.findElement(By.xpath("//*[@id='node-" + Integer.toString(i) + "']"));
// do your logic here
}
|
Cannot loop/iterate through a list of WebElements in Selenium using C#
Tag : chash , By : ugufugu
Date : March 29 2020, 07:55 AM
|