![](/img/trans.png)
[英]How to verify text everytime after posting with Selenium WebDriver using java?
[英]How to verify tooltip text using Selenium WebDriver with java on a webpage
我想驗證我網頁的 NEW Button 上的工具提示文本。 鼠標懸停前 NEW Button 的 html 后端代碼如下:
<button id="newBtn" class="checkForSave" title="Create a new Configuration Package" type="button">New</button>
鼠標懸停在新按鈕上后,新按鈕的 html 后端代碼如下:
<button id="newBtn" class="checkForSave" title="" type="button"> area-describdby="ui-tooltip-27"New</button>
現在我想驗證工具提示文本“創建新的配置包”應該在鼠標懸停在新按鈕上之后出現。
我可以通過以下代碼在鼠標懸停之前將文本存儲在字符串中:
WebElement NewButton = driver.findElement(By.id("newBtn"));
String Tooltip = NewButton.getAttribute("title");
System.out.println(Tooltip);
它的打印文本“創建一個新的配置包”
但是當我將鼠標移到 NEW 按鈕上並編寫代碼時
Actions ActionChains = new Actions(driver);
WebElement NewButton = driver.findElement(By.id("newBtn"));
actions.moveToElement(NewButton).build().perform();
ActionChains.clickAndHold(NewButton).perform();
String Tooltip = NewButton.getAttribute("title");
System.out.println(Tooltip);
我沒有收到任何消息,我收到了空白消息,因為在鼠標懸停之后,NEW Button 的后端 html 代碼中的標題是“”。
我怎樣才能做到這一點?
注釋掉 ActionChains.clickAndHold(NewButton).perform();
import org.openqa.selenium.interactions.HasInputDevices;
import org.openqa.selenium.interactions.Mouse;
import org.openqa.selenium.internal.Locatable;
Locatable hoverItem = (Locatable) webEleObj;
Mouse mouse = ((HasInputDevices) getDriver()).getMouse();
mouse.mouseMove(hoverItem.getCoordinates());
嘗試使用 xpath 查找元素! 它可能對你有幫助,就像我用“id”嘗試過的一樣,但它沒有用,而它使用 xpath 來代替!!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.