I want to click on an item by its visible text inside a specific path here is the code I want to click on these option tag by its value or the inner text based on its path as these values (date picker) are repeated in other sections
Asked
Active
Viewed 484 times
-1
-
3Please do not post screenshots; instead, include the code in your question. – orde Apr 21 '19 at 16:33
-
You can refer this for precise solution. https://stackoverflow.com/questions/55770300/cant-select-a-value-or-enter-value-to-loading-dropdown – Dhru 'soni Apr 22 '19 at 10:34
-
Possible duplicate of [How to select a dropdown value in Selenium WebDriver using Java](https://stackoverflow.com/questions/20138761/how-to-select-a-dropdown-value-in-selenium-webdriver-using-java) – JeffC Apr 22 '19 at 15:06
3 Answers
0
WebElement x=driver.findElement(By.xpath("//select[@class='calendars-month-year']/option[1]"));
String y=x.getAttribute("innerText"); // =1288
if (y.equals("1288"){
x.click();
}
Or directly
driver.findElement(By.xpath("//select[@class='calendars-month-year']/option[1]")).click(); //this will click on the first option

M J
- 174
- 1
- 12
0
I think you are trying to select an option by its visible text value. You can use the following code to do the same:
Select sel = new Select(driver.findElement(By.xpath("//select[@class='calendars-month-year']")));
sel.selectByVisibleText("1289");

Nikunj
- 1
- 1
-
I have the same class 'calender-moth-year' repeated in other section of HTML (2 date picker ) so I want to click on a specific one – Mohammed Esa Apr 22 '19 at 08:52
-
@MohammedEsa Then you need to create a unique locator to find the exact `SELECT` element that you want. We can't help you with that until you post the relevant HTML or preferably a link to the page. – JeffC Apr 22 '19 at 15:08
-1
You can use By.xpath("//option[contains(.,'1290')]")
or By.xpath("//option[text() = '1290']")

Adi Ohana
- 927
- 2
- 13
- 18