我想通过特定路径中的可见文本点击项目here is the code我想通过其值或基于其路径的内部文本单击这些选项标记,因为这些值(日期选择器)在其他部分中重复
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();
}
或直接
driver.findElement(By.xpath("//select[@class='calendars-month-year']/option[1]")).click(); //this will click on the first option
我想你试图通过其可见文本值选择一个选项。您可以使用以下代码执行相同的操作:
Select sel = new Select(driver.findElement(By.xpath("//select[@class='calendars-month-year']")));
sel.selectByVisibleText("1289");
你可以使用By.xpath("//option[contains(.,'1290')]")
或By.xpath("//option[text() = '1290']")