Selenium 有没有办法找到特定的文本并突出显示
我试图搜索文本并突出显示它,但它给我一个错误没有这样的元素:无法定位 我使用的是布尔值,然后我找到了文本,但我不知道如何在selenium中突出显示它Selenium 有没有办法找到特定的文本并突出显示,selenium,Selenium,我试图搜索文本并突出显示它,但它给我一个错误没有这样的元素:无法定位 我使用的是布尔值,然后我找到了文本,但我不知道如何在selenium中突出显示它 myD.getPageSource().contains("Power of Selenium WebDriver with "); boolean Error = myD.getPageSource().contains("frequent test steps as KEYWORDS"); if (Error == true
myD.getPageSource().contains("Power of Selenium WebDriver with ");
boolean Error = myD.getPageSource().contains("frequent test steps as KEYWORDS");
if (Error == true)
{
System.out.print("Text Found");
// highLightElement();
}
else
{
System.out.print("Text not Found");
}
另外,我使用WebElement,但它给我的错误是找不到这样的元素
driver.get("https://anyaut.com/");
WebElement matchedElement=driver.findElement(By.xpath("//*[contains(text(),'frequent test steps as KEYWORDS')]"));
highLightElement(matchedElement);
高亮元素:
public static void highLightElement(WebElement element){
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].setAttribute('style','background: yellow; border: 2px solid red;');", element);
}
查看网站,有以下结构:
<p class="green-border-inner-content">Built using <font color="#34d293">Page Object, Data Driven & Keyword Driven
Automation Frameworks</font>. Has the facility to group frequent test steps as KEYWORDS , along with reusable Test
Data and Element Identifiers.</p>
或者,如果您想继续,您需要修改您的表达方式,使其看起来像:
//*[text()[contains(.,'frequent test steps as KEYWORDS')]]
我不知道您打算如何突出显示找不到的元素?听起来你的定位器坏了,你需要修复它。我们对此无能为力,因为您没有提供指向该页面或相关HTML的链接。这是您没有回答我问题的链接。以及在页面顶部的参考
//*[text()[contains(.,'frequent test steps as KEYWORDS')]]