System.out.println(((JavascriptExecutor)driver).executeScript("return arguments[0].firstChild.textContent;", new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("span.mat-option-text")))).toString());
``` `xpath` :
System.out.println(((JavascriptExecutor)driver).executeScript("return arguments[0].firstChild.textContent;", new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[@class='mat-option-text']")))).toString());
2条答案
按热度按时间lo8azlld1#
您需要执行javascript:
9fkzdhlc2#
文本位于文本节点内。因此,要检索文本,必须为
visibilityOfElementLocated()
您可以使用以下任一定位器策略:cssSelector
:System.out.println(((JavascriptExecutor)driver).executeScript("return arguments[0].firstChild.textContent;", new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[@class='mat-option-text']")))).toString());