Javaの+セレン - アクション - ホバー

一般的なテストシナリオは、2つの共通ポイントを置きます:

最初のものは、ドロップダウンサブメニューが存在することになる、特定の要素の上にホバーです。

第二は、検索処理で入力され、オートコンプリートのフィールドを選択します。

 

ホバーについて、セレンは、ドロップダウンメニューの上にマウスホバーを見て、Actions.javaファイルにこの方法を置きます。

 

パッケージrjcs。

輸入java.text.SimpleDateFormatの。
輸入はjava.util.ArrayList; 
インポートのjava.util.Calendar; 
輸入はjava.util.List; 
輸入java.util.Set; 

輸入org.openqa.selenium.interactions.Actions。
輸入org.apache.commons.io.FileUtils。
輸入org.openqa.selenium.TakesScreenshot; 
輸入org.openqa.selenium.firefox.FirefoxDriver; 
輸入org.openqa.selenium.interactions.Actions。
輸入org.openqa.selenium.By; 
輸入org.openqa.selenium.Keys。
輸入org.openqa.selenium.WebElement; 
輸入org.testng.annotations.Test; 
輸入org.openqa.selenium。* ; 

輸入java.awt.Rectangle;
輸入java.awt.Robot。
java.awt.Toolkitのインポート、
インポートjava.awt.image.BufferedImage; 
インポートはjava.io.File; 
インポートにjava.io.IOException; 

インポートjavax.imageio.ImageIO; 

インポートorg.openqa.selenium.OutputType; 

インポートcom.thoughtworks .selenium.SeleneseTestNgHelper; 

パブリック クラスckqhh 
{ 
    公共 静的 ボイドメイン(文字列[]引数)
    
    { 
         するSystem.setProperty(" webdriver.firefox.bin "" C:\\プログラムファイル(x86の)\\ \\ FirefoxのMozilla Firefoxの。 EXE ");     // インストールパスのFirefoxを設定し、見つけることができないシステムを防止
            
         FirefoxDriverドライバを =新しい新しい FirefoxDriver();         //は、Firefoxブラウザインスタンスを初期化し、ブラウザ開く
         
        試み
        { 
             driver.manage()ウィンドウ()最大化を(); ...          // 最大化されたウィンドウ
             
             のThread.sleep(3000 );         
             
             driver.manage() .window()を最大();.          // ウィンドウ最大化
             
             のThread.sleep(3000 
             

             。ドライバGET" https://www.baidu.com/ " );   
            
             のThread.sleep(5000 ); 
             
             WebElement設定 =ドライバ.findElement(By.xpath("// * [ID @ = 'U1'] / [8] "));    // 设置
             
             アクションアクション = 新しいアクション(ドライバ); 
             action.moveToElement(設定).perform(); 
             
             のThread.sleep(5000 ); 
             
             driver.findElement(By.linkText(" 高级搜索" )))(クリックしてください。。

             
             のThread.sleep(5000 ); 
             
        } キャッチ(例外電子)
        { 
            e.printStackTrace(); 
        } 最後に 
        { 
            driver.quit(); 
        
         } 
   } 
    

}

 

 

 

 

================================================== ================================================== ============

 

 

 

 

パッケージrjcs。

輸入java.text.SimpleDateFormatの。
輸入はjava.util.ArrayList;
インポートのjava.util.Calendar;
輸入はjava.util.List;
輸入java.util.Set; 

輸入org.openqa.selenium.interactions.Actions。
輸入org.apache.commons.io.FileUtils。
輸入org.openqa.selenium.TakesScreenshot;
輸入org.openqa.selenium.firefox.FirefoxDriver;
輸入org.openqa.selenium.interactions.Actions。
輸入org.openqa.selenium.By;
輸入org.openqa.selenium.Keys。
輸入org.openqa.selenium.WebElement;
輸入org.testng.annotations.Test;
輸入 org.openqa.selenium *。; 

輸入java.awt.Rectangle;
輸入java.awt.Robot。
輸入java.awt.Toolkitの。
輸入java.awt.image.BufferedImage;
インポートのjava.io.File;
インポートにjava.io.IOException; 

輸入javax.imageio.ImageIO; 

輸入org.openqa.selenium.OutputType。

輸入com.thoughtworks.selenium.SeleneseTestNgHelper; 

パブリック クラスckqhh 
{ 
    公共 静的 ボイドメイン(文字列[]引数)
    
    {
         するSystem.setProperty( "webdriver.firefox.bin"、 "C:\\プログラムファイル(x86の)\\ \\ firefox.exeをMozilla Firefoxの");     // インストールパスのFirefoxを設定し、システムを防止することが見つけることができません
            
         FirefoxDriverドライバを = 新しい新しい FirefoxDriver();         // 初期Firefoxブラウザインスタンス、およびブラウザを開いて
         
        試してみる
        { 
             driver.manage()ウィンドウ()最大化を(); ...          // 最大化されたウィンドウ
             
             のThread.sleep( 3000 );         
             
             driver.manage() .window()を最大();.          // ウィンドウ最大化
             
             のThread.sleep( 3000 ); 
             
             driver.get("https://www.baidu.com/" );  
             
             のThread.sleep( 5000 ); 
             
             driver.findElement(By.id( "KW"))のSendKeys( "セレンA"。 )。
             
             Thread.sleep( 5000 ); 

             
             // 自动补全其中一个选择项 
             WebElement auto_text = driver.findElement(By.xpath( "// * / DIV / UL /李[ID = '形' @] [データキー@ = 'セレンAPI']" )); 
             
             アクションアクション = 新しいアクション(ドライバ); 
             action.moveToElement(auto_text).click()()を実行します。


             
             Thread.sleep( 5000 ); 
             
        } キャッチ(例外e)
        {
            e.printStackTrace(); 
        } 最後に 
        { 
            driver.quit()。
        
         } 
   } 
    

}

おすすめ

転載: www.cnblogs.com/xiaobaibailongma/p/12217944.html