<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      selenium webdriver 右鍵另存為下載文件(結(jié)合robot and autoIt)

      首先感謝Lakshay Sharma 大神的指導(dǎo)

      最近一直在研究selenium webdriver右鍵菜單,發(fā)現(xiàn)selenium webdriver 無法操作瀏覽器右鍵菜單,如圖

      如果我想右鍵另存為,根本操作不了。

      也有在網(wǎng)上看到webdriver right click option的一些代碼,拿來用發(fā)現(xiàn)不能用的。

      Actions act = new Actions(driver);
       
      WebElement link = driver.findElement(By.id("xpath"));
       
      act.moveToElement(link).contextClick().sendKeys(Keys.ArrowsDown).build().perform();

      使用Actions沒辦法拿到右鍵菜單。

      后來在某論壇發(fā)帖,一個印度籍的專家給出solution, perfect!完美解決

      http://forumsqa.com/question/how-to-click-the-option-of-the-menu-which-the-right-click-pop-up/

      方案如下:

      1.selenium 彈出右鍵菜單

      2.robot選擇相關(guān)菜單

      3.調(diào)用autoIt實現(xiàn)windows gui另存操作

      tips: 

      目測autoIt沒法操作web elements,比如我當(dāng)前使用autoIt獲取富文本框,卻沒法拿到相關(guān)的 classs,拿到的只能是瀏覽器的信息

      廢話不多說,test case 如下

      1.打開autoIt的官網(wǎng)

      2.click download 頁面

      3.選擇autoIt下載圖標(biāo),單擊右鍵另存為

      4.在彈出另存為窗口輸入指定路徑,單擊保存

      如果您有selenium基礎(chǔ),1~2都很easy。 調(diào)出右鍵菜單只需要action的contexClick方法

      Action.contextClick(myElement).build().perform();

      接下來就是選擇右鍵菜單的另存為

      使用robot,模擬鍵盤操作,使用方向鍵

      Robot robot = new Robot();
       
      // This will bring the selection down one by one
       
      robot.keyPress(KeyEvent.VK_DOWN);
       
      Thread.sleep(1000);
       
      robot.keyPress(KeyEvent.VK_DOWN);
       
      Thread.sleep(1000);
       
      robot.keyPress(KeyEvent.VK_DOWN);
       
      Thread.sleep(1000);
       
      robot.keyPress(KeyEvent.VK_DOWN);
       
      Thread.sleep(1000);
       
      // This is to release the down key, before this enter will not work
       
      robot.keyRelease(KeyEvent.VK_DOWN);
       
      Thread.sleep(1000);
       
      robot.keyPress(KeyEvent.VK_ENTER);

       

      接下來就該交給autoIt處理另存為窗口

      autoIt使用方法:

      依次定位保存按鈕,使用ControlFocus方法,定位編輯框(文件名)title是“另存為”,class是Edit ,instance 是1 

      然后使用ControlSetText方法輸入保存路徑,定位保存按鈕,使用ControlClick方法單擊保存按鈕

       

      ControlFocus("另存為", "","Edit1");ControlFocus("title","text",controlID) Edit1=Edit instance 1
      ; Wait 10 seconds for the Upload window to appear
      
        WinWait("[CLASS:#32770]","",10)
      
      ; Set input focus to the edit control of Upload window using the handle returned by WinWait
      
        ControlFocus("另存為","","Edit1")
      
        Sleep(2000)
      
      ; Set the File name text on the Edit field
      
        ControlSetText("另存為", "", "Edit1", "d:\autoit-v3-setup")
      
        Sleep(2000)
      
      ; Click on the Open button
      
        ControlClick("另存為", "","Button1");

      然后使用autoIt轉(zhuǎn)換為EXE格式的可執(zhí)行文件

      使用java的runTime類調(diào)用

      Runtime.getRuntime().exec("E:\\test\\download.exe");

      全部代碼如下:

      package com.packt.webdriver.chapter2;
      
       
      
      import java.awt.AWTException;
      import java.awt.Robot;
      import java.awt.event.KeyEvent;
      import java.io.File;
      import java.io.IOException;
      
       
      
      import java.util.List;
      import java.util.concurrent.TimeUnit;
      
      import org.apache.commons.io.FileUtils;
       
      import org.openqa.selenium.By;
      import org.openqa.selenium.JavascriptExecutor;
      import org.openqa.selenium.Keys;
      import org.openqa.selenium.OutputType;
      import org.openqa.selenium.TakesScreenshot;
      import org.openqa.selenium.WebDriver;
      //import org.openqa.selenium.WebDriver.Navigation;
      import org.openqa.selenium.WebElement;
      import org.openqa.selenium.chrome.ChromeDriver;
      import org.openqa.selenium.chrome.ChromeOptions;
      import org.openqa.selenium.firefox.FirefoxDriver;
      import org.openqa.selenium.interactions.Actions;
      
      import com.thoughtworks.selenium.Selenium;
      import com.thoughtworks.selenium.webdriven.WebDriverBackedSelenium;
       
      
       
      
      public class AutoItDownload  {
          
      
      
          public static void main (String [] args) throws InterruptedException, AWTException
          {
               
           
              String URL="https://www.autoitscript.com";
              //avoid Chrome warnning message like "unsupported command-line flag --ignore-certificate-errors. "
              ChromeOptions options = new ChromeOptions();
              options.addArguments("--test-type");
             
              System.setProperty("webdriver.chrome.driver", "E:\\chromedriver.exe");  
              WebDriver driver = new ChromeDriver(options);
               //WebDriver driver = new FirefoxDriver();
             
              driver.get(URL);
           
      
              driver.manage().window().maximize(); 
              driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
              driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
              WebElement editor=driver.findElement(By.xpath("http://*[@id='menu-item-207']"));
              Actions actions=new Actions(driver);
              actions.moveToElement(editor).perform();
              //locate download link
              WebElement d=driver.findElement(By.xpath("http://*[@id='menu-item-209']/a"));
              d.click();
             
              Thread.sleep(5000);
              //right click the download link
            
             
              //locate download link
          
             
              //right click the download link
              WebElement download=driver.findElement(By.xpath("http://img[starts-with(@alt,'download autoit')]"));//*[@id="content-area"]/div/table/tbody/tr[1]/td[2]/p/a/img
              JavascriptExecutor js=(JavascriptExecutor)driver;
              // roll down and keep the element to the center of browser
              js.executeScript("arguments[0].scrollIntoView(true);", download);
              actions.moveToElement(download).contextClick().build().perform();
              Robot robot = new Robot();
              
           // This will bring the selection down one by one
            
           robot.keyPress(KeyEvent.VK_DOWN);
            
           Thread.sleep(1000);
            
           robot.keyPress(KeyEvent.VK_DOWN);
            
           Thread.sleep(1000);
            
           robot.keyPress(KeyEvent.VK_DOWN);
            
           Thread.sleep(1000);
            
           robot.keyPress(KeyEvent.VK_DOWN);
            
           Thread.sleep(1000);
            
          // robot.keyPress(KeyEvent.VK_DOWN);
            
           //Thread.sleep(1000);
            
           // This is to release the down key, before this enter will not work
            
           robot.keyRelease(KeyEvent.VK_DOWN);
            
           Thread.sleep(1000);
            
           robot.keyPress(KeyEvent.VK_ENTER);
             
              
              // this code block will snapshot the browser
              File scrShot=new File("d:\\1.png");
              File scrFile= ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
              try {
                  
                  FileUtils.copyFile(scrFile, scrShot);
              } catch (IOException e) {
                  // TODO Auto-generated catch block
                  System.out.println("Can't save screenshot");
                  e.printStackTrace();
              } 
              finally
              {
                 
                  System.out.println("screen shot finished");
              }
             // System.out.println(scrFile.getAbsolutePath());
              
              //call autoIt to save the file
              try {
                  Runtime.getRuntime().exec("E:\\test\\download.exe");
              } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
              
              Thread.sleep(150000);
              driver.quit();
        
            
          }
          
      }

      效果圖:

      posted @ 2014-09-13 00:41  to be crazy  閱讀(28894)  評論(3)    收藏  舉報
      主站蜘蛛池模板: 老司机精品影院一区二区三区| 一边吃奶一边做动态图| 青草99在线免费观看| 亚洲永久一区二区三区在线| 肥臀浪妇太爽了快点再快点| 免费无码黄十八禁网站| 亚洲午夜无码久久久久小说| 波多结野衣一区二区三区| 亚洲av无码专区在线亚| 亚洲天天堂天堂激情性色| 来安县| 污污网站18禁在线永久免费观看| 亚洲 一区二区 在线| 好吊妞无缓冲视频观看| 成人无码午夜在线观看| 欧美熟妇乱子伦XX视频| 濉溪县| 亚洲国产午夜福利精品| 郯城县| 精品一区二区三区蜜桃久| 欧美日韩国产综合草草| 米奇影院888奇米色99在线| 国内不卡的一区二区三区| 久久五月丁香激情综合| 亚洲中文字幕无码专区| 女同亚洲精品一区二区三| 国产三级精品福利久久| 久久久久免费看黄a片app| 无码少妇一区二区| 久久综合色之久久综合| 亚洲色一区二区三区四区| 精品国产av无码一区二区三区| 蜜臀精品一区二区三区四区| 18禁成人免费无码网站| 日韩人妻精品中文字幕| 亚洲国产欧美在线观看片| 人妻少妇不满足中文字幕| 国产精品亚洲аv无码播放| 色吊丝永久性观看网站| 国产一区二区三区四区激情| 玩弄丰满少妇人妻视频|