// Find and click on the link
WebElement link = driver.findElement(By.linkText("Your Link Text"));
link.click();
// Wait for the link to become disabled
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.attributeToBe(link, "disabled", "true"));
// Perform validation or assertions here
boolean isLinkDisabled = link.getAttribute("disabled").equals("true");
System.out.println("Is link disabled? " + isLinkDisabled);
// find and click on the link
driver.findElement(By.xpath("//input[@name='link']")).click();
// validate if the link is disabled
try
{
driver.findElement(By.xpath("//input[@name='link' and @disabled]"));
System.out.println("Link was disabled");
}
catch(NoSuchElementException ex)
{
System.out.println("Link wasn't disabled");
}
2条答案
按热度按时间hkmswyz61#
您可以按照以下步骤操作:
findElement(By)
或findElements(By)
)根据link元素的属性(例如,ID、class或XPath)查找它。click()
方法单击链接。moiiocjp2#
HTML
disabled
Attributeboolean
disabled
属性,当存在时,使元素不可变,不可聚焦,甚至不能与表单一起提交。用户不能编辑或关注控件及其窗体控件的子控件。例如:
本用例
因此,要验证是否单击链接,该链接将被禁用,直到重定向到下一页,您可以使用以下策略: