这是我的文本区域,我想单击任何一个单词,假设我想单击“星期六”,但是这个 xpath 给出了整个文本区域,无法单击任何一个单词。请让我知道如何使用 Java selenium 来做到这一点
我尝试了xpath和doubleClick方法
//you need to use js, firstly focus the entire text, then search the word //you need then select it and click on it using js executar
WebElement textArea = driver.findElement(By.id("ai-script.....ETC"));
String theWordYouNeedToClick = "Saturday";
String script = "var textArea = arguments[0]; " +
"textArea.focus(); " +
"var start = textArea.value.indexOf('" + theWordYouNeedToClick + "'); " +
"var end = start + '" + theWordYouNeedToClick + "'.length; " +
"textArea.setSelectionRange(start, end); "
((JavascriptExecutor) driver).executeScript(script, textArea);
你需要使用js,首先聚焦整个文本,然后搜索你需要的单词然后选择它并使用js执行器点击它
WebElement textArea = driver.findElement(By.id("ai-script.....ETC"));
String theWordYouNeedToClick = "Saturday";
String script = "var textArea = arguments[0]; " +
"textArea.focus(); " +
"var start = textArea.value.indexOf('" + theWordYouNeedToClick + "'); " +
"var end = start + '" + theWordYouNeedToClick + "'.length; " +
"textArea.setSelectionRange(start, end); "
((JavascriptExecutor) driver).executeScript(script, textArea);