我想根据特定路径中的内部文本单击一个项目

问题描述 投票:-1回答:3

我想通过特定路径中的可见文本点击项目here is the code我想通过其值或基于其路径的内部文本单击这些选项标记,因为这些值(日期选择器)在其他部分中重复

java selenium selenium-webdriver selenium-chromedriver ui-automation
3个回答
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();
    }

或直接

driver.findElement(By.xpath("//select[@class='calendars-month-year']/option[1]")).click(); //this will click on the first option

0
投票

我想你试图通过其可见文本值选择一个选项。您可以使用以下代码执行相同的操作:

Select sel = new Select(driver.findElement(By.xpath("//select[@class='calendars-month-year']")));
sel.selectByVisibleText("1289");

-1
投票

你可以使用By.xpath("//option[contains(.,'1290')]")By.xpath("//option[text() = '1290']")

© www.soinside.com 2019 - 2024. All rights reserved.