Issue
I Have an two string in Auto suggestion Dropdown Like 1. qapostgres112axdef 2. qapostgres112
I need to match the second value (qapostgres112) and need to click on it. for that I used the contains() method. since, both the String contains the same characters 'qapostgres112' selenium performs click operation on first string.
driver.findElement(By.xpath("//span[@role=\"combobox\"]")).click();
WebElement project = driver.findElement(By.xpath("//input[@type=\"search\"]"));
project.click();
project.sendKeys("qapostgres112");
List<WebElement> ddown = driver.findElements(By.xpath("//span[@class=\"select2-dropdown select2-dropdown--below\"]"));
for (WebElement element : ddown) {
if (element.getText().contains("qapostgres112"))
element.click();
}
}
Solution
Since both the options contain qapostgres112
, the contains() method will select the first partial match. You can use text(), it checks the exact match.
Example:
//tagname[text()='qapostgres112']
Answered By - Pooja Jadhav
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.