下面是HTML:
<select size="1" id="F_21__3" class="c3" style="position: absolute; left: 127px; top: 173px; width: 148px; height: 14px; font-style: normal; font-weight: normal; text-decoration: none; text-shadow: none; font-stretch: normal;" disabled="disabled">
<option value="I" des="Item">Item</option>
<option value="S" des="Service">Service</option>
</select>
如何使用Selenium + Java检查文本"Service“是否可见?
发布于 2018-08-06 20:39:57
检查是否选择了“Services”的代码:
WebElement selectedByDefault= driver.findElement(By.xpath("//select[@id='F_21__3']"));
Select select = new Select(selectedByDefault);
if(select.getFirstSelectedOption().equals("Service"))
{
System.out.println("Services is displayed by Default.");
}
发布于 2018-09-12 18:42:58
检查文本“Service”是否可见的代码
String checkTextVisible = driver.findElement(By.xpath("//*[contains(text(),'Service')]").getText();
if(checkTextVisible.equals("Service")){
System.out.println(checkTextVisible + " text is visible");
}
发布于 2020-06-01 22:01:07
该字段是禁用还是启用并不重要。你只需要找到正确的选择器,然后你就可以很容易地检查它了。
String actualText = driver.findElemeny(By.cssSelector("yourSelector")).getAttribut("value");
Assert.assertEqual(actualText, "Service");
或者更简单(但前提是Service不会出现在页面的其他位置)。
boolean presence = false;
if(driver.getPageSource().contains("Service")){
System.out.println("Text is present");
presence = true;
}else{
System.out.println("Text is absent");}
Assert.assertTrue(presence);
https://stackoverflow.com/questions/51707504
复制相似问题