我有一个由jquery通过验证添加的引导工具提示。我需要在Selenium上测试它(Tooltip它自己不会被Selenium弹出)。我尝试了所有方法,但没有运气。
我使用的是Firefox 51v。和Maven版本:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.0</version>
<scope>test</scope>
</dependency>
HTML code:
<input id="ele-id" class="text-right red-tooltip" maxlength="10" ng-change="validateFun()" data-original-title="" title="" type="text">
在Javascript中:
$('#ele-id').tooltip({title: 'Must be between 0 and 1', placement: 'right'});
和我的Java测试代码:
WebElement element = driver.findElement(By.id("ele-id"));
String initialVal = element.getAttribute("value");
element.clear();
element.sendKeys("-1");
//element.click();
Actions action = new Actions(driver);
//action.moveToElement(element).build().perform();
action.clickAndHold(element).perform();
//JavascriptExecutor executor = (JavascriptExecutor)driver; executor.executeScript("arguments[0].click();", element);
Thread.sleep(2000);
WebElement toolTipElement = driver.findElement(By.className("tooltip"));
String toolTipText = toolTipElement.getText();
Assert.assertEquals("Must be between 0 and 1", toolTipText);
我为更多代码感到抱歉我在这里粘贴,我也尝试过评论代码。
答案 0 :(得分:0)
尝试鼠标悬停事件
Actions actions = new Actions(driver);
actions.moveToElement(element);
actions.perform();
答案 1 :(得分:0)
我没有聚焦并再次聚焦元素,以便我能够阅读工具提示。
ikwattro@graphaware-team ~/d/_/310> ./bin/neo4j-shell -file result.cypher
Transaction started
Transaction committed
Transaction started
+-------------------+
| No data returned. |
+-------------------+
Nodes created: 4
Relationships created: 3
Properties set: 8
Labels added: 4
52 ms
Transaction committed