2016-06-22 5 views
0

イメージのツールヒントテキストを取得しようとしていて、変数に保存したかったのです。以下は、HTML Code.scriptがマウスのホバーイベントを実行し、ツールチップのテキスト値を表示することができますが、ツールチップのテキスト値を取得することができません。セレンウェブドライバを使用してツールヒントテキストを取得する方法

<img onmouseover="var relNo=getReleaseNo(); this.T_ABOVE = false; this.T_OFFSETY=-10; this.T_OFFSETX=10; this.T_WIDTH=200; this.T_DELAY=1000; return escape('&lt;table&gt;&lt;tr&gt;&lt;td align=center&gt;Welcome to the Daimler EngineeringPortal&lt;br&gt;&lt;b&gt;' + relNo + '&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;');" src="./pics/logo/logo_mini.jpg"> 

PFA以下はセレンスクリプトです。スクリプトでは、すべてのものがテキストを取得することができないexppectを働いています。
セレンスクリプト

package All_Module_Engp; 

import java.io.File; 

import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.firefox.FirefoxBinary; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.openqa.selenium.firefox.FirefoxProfile; 
import org.openqa.selenium.interactions.Action; 
import org.openqa.selenium.interactions.Actions; 

public class Engp_Module { 
    public static void main(String args[]) 
    { 
     File pathToBinary = new File("C:/Users/rrimjhi/AppData/Local/Mozilla Firefox/firefox.exe"); 
     FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary); 
     FirefoxProfile firefoxProfile = new FirefoxProfile();  
     WebDriver driver = new FirefoxDriver(ffBinary,firefoxProfile); 
     driver.get("https://tindito.COM"); 
      driver.findElement(By.id("usr")).sendKeys("xyz123"); 
      driver.findElement(By.id("password")).sendKeys("xyz123"); 
      driver.findElement(By.name("login")).click(); 
      driver.manage().window().maximize(); 
//   String s = driver.getTitle(); 

//   System.out.println(s); 
      Actions tooltip = new Actions(driver); 
      driver.switchTo().frame("header"); 
      WebElement img1=driver.findElement(By.xpath("//img[@src='./pics/logo/logo_mini.jpg']")); 
      tooltip.clickAndHold(img1).perform(); 

      String ToolTipText = img1.getText(); 

      System.out.println(ToolTipText); 
    } 


} 

答えて

0

これを試してみてください:

WebElement elementWithTooltip = driver.findElement(By.xpath("//img[@src='./pics/logo/logo_mini.jpg']")); 
Actions builder = new Actions(driver); 
builder.moveToElement(elementWithTooltip).build().perform(); 
//try to find this tool tip element and verify the text 
WebElement tooltip = driver.findElement(By.id("tooltip")); 
assertEquals("tooltip content", tooltip.getText()); 
+0

ありません、それは – Rimjhim

+0

に動作していない私は、コードが何を行っている見ることができます? –

+0

アクションtooltip =新しいアクション(ドライバ); \t \t \t driver.switchTo()。frame( "header"); \t \t \t WebElement img1 = driver.findElement(By.xpath( "// img [@src = '。/ pics/logo/logo_mini.jpg']")); \t \t tooltip.clickAndHold(img1).perform(); \t \t driver.manage()。timeouts()。implicitlyWait(50、TimeUnit.SECONDS); – Rimjhim

関連する問題