硒测试非活动按钮的工具提示

selenium testing a tooltip for an inactive button

我可以点击的人,点击 时,没有任何反应,即该操作被禁用。但是,会显示一个工具提示。只有当我们关注按钮时,工具提示才会出现。

按钮的html如下:

     <button type="button" style="color:#ffffff;" rel="rel-517347" data-toggle="popover" data-animation="true" data-placement="top" data-html="true" data-trigger="hover" data-content="<span class='text-center'>
    <div>Ride can only be edited before </div><div>1 hour of pickup time.</div>
</span>" class="btn btn-default disbleBtn width_100" data-original-title="" title="">Edit Ride</button>

Ride 只能在工具提示之前编辑。

我如何验证工具提示的文本,因为它不断被破坏。

注意这里的 isEnabled() 函数 returns 为真,因为我可以点击按钮,但没有任何动作发生。

有什么方法可以验证按钮的 class 即 btn btn-default disbleBtn width_100 吗? 有什么功能或方法吗?

我猜你需要悬停而不是点击按钮。当显示悬停工具提示时,您会立即单击并且工具提示消失了。 使用 chrome devtools 手动执行此操作,打开 devtools-> sources 选项卡,将鼠标悬停在按钮上并按 F8 暂停,然后检查工具提示元素。获得工具提示选择器后,请尝试以下代码:

new Actions(driver).moveToElement(buttonElement).perform();
String tooltipText = new WebDriverWait(driver, 10)
    .until(ExpectedConditions.visibilityOfElementLocated(toolTipLocator).getText();
//Verify

或者试试这个:

new Actions(driver).moveToElement(buttonElement).perform();
new WebDriverWait(driver, 10)
    .until(ExpectedConditions.textToBePresentInElementLocated(toolTipLocator, textToVerify)