Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我想根据特定路径内的内部文本单击一个项目_Java_Selenium_Selenium Webdriver_Selenium Chromedriver_Ui Automation - Fatal编程技术网

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

Java 我想根据特定路径内的内部文本单击一个项目,java,selenium,selenium-webdriver,selenium-chromedriver,ui-automation,Java,Selenium,Selenium Webdriver,Selenium Chromedriver,Ui Automation,我想通过特定路径中的可见文本单击某个项目 我想按其值或基于其路径的内部文本单击这些选项标记,因为这些值(日期选择器)在其他部分重复您可以使用by.xpath(“//option[contains(,'1290')]”或by.xpath(“//option[text()='1290']) 或者直接 driver.findElement(By.xpath("//select[@class='calendars-month-year']/option[1]")).click(); //this wil

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

您可以使用
by.xpath(“//option[contains(,'1290')]”
by.xpath(“//option[text()='1290'])

或者直接

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");

请不要发布截图;相反,在你的问题中包含代码。你可以参考这个来获得精确的解决方案。可能重复的我有相同的类'日历蛾年'在HTML的其他部分重复(2日期选择器),所以我想点击一个特定的one@MohammedEsa然后,您需要创建一个唯一的定位器来查找所需的确切
选择
元素。在您发布相关HTML或最好是页面链接之前,我们无法为您提供帮助。没有理由这样做,因为它是
SELECT
元素。没有理由这样做,因为它是
SELECT
元素。
Select sel = new Select(driver.findElement(By.xpath("//select[@class='calendars-month-year']")));
sel.selectByVisibleText("1289");