selenium webdriver學(xué)習(xí)16用selenium webdriver實現(xiàn)selenium RC中的類似的方法

最近想總結(jié)一下學(xué)習(xí)selenium webdriver的情況孽文,于是就想用selenium
webdriver里面的方法來實現(xiàn)selenium RC中操作的一些方法。目前封裝了一個ActionDriverHelper類真友,來實現(xiàn)RC中Selenium.java和 DefaultSelenium.java中的方法。有一些方法還沒有實現(xiàn)紧帕,寫的方法大多沒有經(jīng)過測試盔然,僅供參考桅打。代碼如下:

package core;  

import java.io.File;  

import java.io.IOException;  

import java.util.HashSet;  

import java.util.List;  

import java.util.Set;  

import java.util.concurrent.TimeUnit;  

  

import org.apache.commons.io.FileUtils;  

import org.openqa.selenium.By;  

import org.openqa.selenium.Cookie;  

import org.openqa.selenium.Dimension;  

import org.openqa.selenium.JavascriptExecutor;  

import org.openqa.selenium.Keys;  

import org.openqa.selenium.NoSuchElementException;  

import org.openqa.selenium.OutputType;  

import org.openqa.selenium.Point;  

import org.openqa.selenium.TakesScreenshot;  

import org.openqa.selenium.WebDriver;  

import org.openqa.selenium.WebElement;  

import org.openqa.selenium.WebDriver.Timeouts;  

import org.openqa.selenium.interactions.Actions;  

import org.openqa.selenium.support.ui.Select;  

  

public class ActionDriverHelper {  

        protected WebDriver driver;  

        public ActionDriverHelper(WebDriver driver){  

            this.driver = driver ;  

        }  

          

          

        public void click(By by) {  

            driver.findElement(by).click();  

        }  

          

        public void doubleClick(By by){  

            new Actions(driver).doubleClick(driver.findElement(by)).perform();  

        }  

          

        public void contextMenu(By by) {  

            new Actions(driver).contextClick(driver.findElement(by)).perform();  

        }  

          

        public void clickAt(By by,String coordString) {  

            int index = coordString.trim().indexOf(',');  

            int xOffset = Integer.parseInt(coordString.trim().substring(0, index));  

            int yOffset = Integer.parseInt(coordString.trim().substring(index+1));  

            new Actions(driver).moveToElement(driver.findElement(by), xOffset, yOffset).click().perform();  

        }  

          

        public void doubleClickAt(By by,String coordString){  

            int index = coordString.trim().indexOf(',');  

            int xOffset = Integer.parseInt(coordString.trim().substring(0, index));  

            int yOffset = Integer.parseInt(coordString.trim().substring(index+1));  

            new Actions(driver).moveToElement(driver.findElement(by), xOffset, yOffset)  

                                .doubleClick(driver.findElement(by))  

                                .perform();  

        }  

          

        public void contextMenuAt(By by,String coordString) {  

            int index = coordString.trim().indexOf(',');  

            int xOffset = Integer.parseInt(coordString.trim().substring(0, index));  

            int yOffset = Integer.parseInt(coordString.trim().substring(index+1));  

            new Actions(driver).moveToElement(driver.findElement(by), xOffset, yOffset)  

                                .contextClick(driver.findElement(by))  

                                .perform();  

        }  

          

        public void fireEvent(By by,String eventName) {  

            System.out.println("webdriver 不建議使用這樣的方法,所以沒有實現(xiàn)愈案。");  

        }  

          

        public void focus(By by) {  

            System.out.println("webdriver 不建議使用這樣的方法挺尾,所以沒有實現(xiàn)。");  

        }  

          

        public void keyPress(By by,Keys theKey) {  

            new Actions(driver).keyDown(driver.findElement(by), theKey).release().perform();          

        }  

          

        public void shiftKeyDown() {  

            new Actions(driver).keyDown(Keys.SHIFT).perform();  

        }  

          

        public void shiftKeyUp() {  

            new Actions(driver).keyUp(Keys.SHIFT).perform();  

        }  

          

        public void metaKeyDown() {  

            new Actions(driver).keyDown(Keys.META).perform();  

        }  

  

        public void metaKeyUp() {  

            new Actions(driver).keyUp(Keys.META).perform();  

        }  

  

        public void altKeyDown() {  

            new Actions(driver).keyDown(Keys.ALT).perform();  

        }  

  

        public void altKeyUp() {  

            new Actions(driver).keyUp(Keys.ALT).perform();  

        }  

  

        public void controlKeyDown() {  

            new Actions(driver).keyDown(Keys.CONTROL).perform();  

        }  

  

        public void controlKeyUp() {  

            new Actions(driver).keyUp(Keys.CONTROL).perform();  

        }  

          

        public void KeyDown(Keys theKey) {  

            new Actions(driver).keyDown(theKey).perform();  

        }  

        public void KeyDown(By by,Keys theKey){  

            new Actions(driver).keyDown(driver.findElement(by), theKey).perform();  

        }  

          

        public void KeyUp(Keys theKey){  

            new Actions(driver).keyUp(theKey).perform();  

        }  

          

        public void KeyUp(By by,Keys theKey){  

            new Actions(driver).keyUp(driver.findElement(by), theKey).perform();  

        }  

          

        public void mouseOver(By by) {  

            new Actions(driver).moveToElement(driver.findElement(by)).perform();  

        }  

          

        public void mouseOut(By by) {  

            System.out.println("沒有實現(xiàn)站绪!");  

            //new Actions(driver).moveToElement((driver.findElement(by)), -10, -10).perform();  

        }  

          

        public void mouseDown(By by) {  

            new Actions(driver).clickAndHold(driver.findElement(by)).perform();  

        }  

          

        public void mouseDownRight(By by) {  

            System.out.println("沒有實現(xiàn)遭铺!");  

        }  

          

        public void mouseDownAt(By by,String coordString) {  

            System.out.println("沒有實現(xiàn)!");  

        }  

  

        public void mouseDownRightAt(By by,String coordString) {  

            System.out.println("沒有實現(xiàn)恢准!");  

        }  

  

        public void mouseUp(By by) {  

            System.out.println("沒有實現(xiàn)魂挂!");  

        }  

  

        public void mouseUpRight(By by) {  

            System.out.println("沒有實現(xiàn)!");  

        }  

  

        public void mouseUpAt(By by,String coordString) {  

            System.out.println("沒有實現(xiàn)馁筐!");  

        }  

  

        public void mouseUpRightAt(By by,String coordString) {  

            System.out.println("沒有實現(xiàn)涂召!");  

        }  

  

        public void mouseMove(By by) {  

            new Actions(driver).moveToElement(driver.findElement(by)).perform();  

        }  

  

        public void mouseMoveAt(By by,String coordString) {  

            int index = coordString.trim().indexOf(',');  

            int xOffset = Integer.parseInt(coordString.trim().substring(0, index));  

            int yOffset = Integer.parseInt(coordString.trim().substring(index+1));  

            new Actions(driver).moveToElement(driver.findElement(by),xOffset,yOffset).perform();  

        }  

        public void type(By by, String testdata) {  

            driver.findElement(by).clear();   

            driver.findElement(by).sendKeys(testdata);  

        }  

  

        public void typeKeys(By by, Keys key) {  

            driver.findElement(by).sendKeys(key);  

        }  

        public void setSpeed(String value) {  

             System.out.println("The methods to set the execution speed in WebDriver were deprecated");  

        }  

  

        public String getSpeed() {  

            System.out.println("The methods to set the execution speed in WebDriver were deprecated");  

            return null;  

              

        }  

        public void check(By by) {  

            if(!isChecked(by))  

                click(by);        

        }  

  

        public void uncheck(By by) {  

            if(isChecked(by))   

                click(by);        

        }  

          

        public void select(By by,String optionValue) {  

            new Select(driver.findElement(by)).selectByValue(optionValue);  

        }  

          

        public void select(By by,int index) {  

            new Select(driver.findElement(by)).selectByIndex(index);  

        }  

  

        public void addSelection(By by,String optionValue) {  

            select(by,optionValue);  

        }  

        public void addSelection(By by,int index) {  

            select(by,index);  

        }  

          

        public void removeSelection(By by,String value) {  

            new Select(driver.findElement(by)).deselectByValue(value);  

        }  

          

        public void removeSelection(By by,int index) {  

            new Select(driver.findElement(by)).deselectByIndex(index);  

        }  

  

        public void removeAllSelections(By by) {  

            new Select(driver.findElement(by)).deselectAll();  

        }  

          

        public void submit(By by) {  

            driver.findElement(by).submit();  

        }  

          

        public void open(String url) {  

            driver.get(url);  

        }  

          

        public void openWindow(String url,String handler) {  

            System.out.println("方法沒有實現(xiàn)!");  

        }  

  

        public void selectWindow(String handler) {  

            driver.switchTo().window(handler);  

        }  

          

        public String getCurrentHandler(){  

            String currentHandler = driver.getWindowHandle();  

            return currentHandler;  

        }  

          

        public String getSecondWindowHandler(){  

            Set<String> handlers = driver.getWindowHandles();  

            String reHandler = getCurrentHandler();  

            for(String handler : handlers){  

                if(reHandler.equals(handler))  continue;  

                reHandler = handler;  

            }  

            return reHandler;  

        }  

          

        public void selectPopUp(String handler) {  

            driver.switchTo().window(handler);  

        }  

          

        public void selectPopUp() {  

            driver.switchTo().window(getSecondWindowHandler());  

        }  

          

        public void deselectPopUp() {  

            driver.switchTo().window(getCurrentHandler());  

        }  

          

        public void selectFrame(int index) {  

            driver.switchTo().frame(index);  

        }  

          

        public void selectFrame(String str) {  

            driver.switchTo().frame(str);  

        }  

          

        public void selectFrame(By by) {  

            driver.switchTo().frame(driver.findElement(by));  

        }  

        public void waitForPopUp(String windowID,String timeout) {  

            System.out.println("沒有實現(xiàn)");  

        }  

        public void accept(){  

            driver.switchTo().alert().accept();  

        }  

        public void dismiss(){  

            driver.switchTo().alert().dismiss();  

        }  

        public void chooseCancelOnNextConfirmation() {  

            driver.switchTo().alert().dismiss();  

        }  

          

        public void chooseOkOnNextConfirmation() {  

            driver.switchTo().alert().accept();  

        }  

  

        public void answerOnNextPrompt(String answer) {  

            driver.switchTo().alert().sendKeys(answer);  

        }  

          

        public void goBack() {  

            driver.navigate().back();  

        }  

  

        public void refresh() {  

            driver.navigate().refresh();  

        }  

          

        public void forward() {  

            driver.navigate().forward();  

        }  

          

        public void to(String urlStr){  

            driver.navigate().to(urlStr);  

        }  

          

        public void close() {  

            driver.close();  

        }  

          

        public boolean isAlertPresent() {  

            Boolean b = true;  

            try{  

                driver.switchTo().alert();  

            }catch(Exception e){  

                b = false;  

            }  

            return b;  

        }  

  

        public boolean isPromptPresent() {  

            return isAlertPresent();  

        }  

  

        public boolean isConfirmationPresent() {  

            return isAlertPresent();  

        }  

  

        public String getAlert() {  

            return driver.switchTo().alert().getText();  

        }  

  

        public String getConfirmation() {  

            return getAlert();  

        }  

  

        public String getPrompt() {  

            return getAlert();  

        }  

  

        public String getLocation() {  

            return driver.getCurrentUrl();  

        }  

          

        public String getTitle(){  

            return driver.getTitle();         

        }  

          

        public String getBodyText() {  

            String str = "";  

            List<WebElement> elements = driver.findElements(By.xpath("http://body//*[contains(text(),*)]"));  

            for(WebElement e : elements){  

                str += e.getText()+" ";  

            }  

             return str;  

        }  

  

        public String getValue(By by) {  

            return driver.findElement(by).getAttribute("value");  

        }  

  

        public String getText(By by) {  

            return driver.findElement(by).getText();  

        }  

  

        public void highlight(By by) {  

            WebElement element = driver.findElement(by);  

            ((JavascriptExecutor)driver).executeScript("arguments[0].style.border = \"5px solid yellow\"",element);   

        }  

  

        public Object getEval(String script,Object... args) {  

            return ((JavascriptExecutor)driver).executeScript(script,args);  

        }  

        public Object getAsyncEval(String script,Object... args){  

            return  ((JavascriptExecutor)driver).executeAsyncScript(script, args);  

        }  

        public boolean isChecked(By by) {  

            return driver.findElement(by).isSelected();  

        }  

        public String getTable(By by,String tableCellAddress) {  

            WebElement table = driver.findElement(by);  

            int index = tableCellAddress.trim().indexOf('.');  

            int row =  Integer.parseInt(tableCellAddress.substring(0, index));  

            int cell = Integer.parseInt(tableCellAddress.substring(index+1));  

             List<WebElement> rows = table.findElements(By.tagName("tr"));  

             WebElement theRow = rows.get(row);  

             String text = getCell(theRow, cell);  

             return text;  

        }  

        private String getCell(WebElement Row,int cell){  

             List<WebElement> cells;  

             String text = null;  

             if(Row.findElements(By.tagName("th")).size()>0){  

                cells = Row.findElements(By.tagName("th"));  

                text = cells.get(cell).getText();  

             }  

             if(Row.findElements(By.tagName("td")).size()>0){  

                cells = Row.findElements(By.tagName("td"));  

                text = cells.get(cell).getText();  

             }  

            return text;  

               

        }  

  

        public String[] getSelectedLabels(By by) {  

                Set<String> set = new HashSet<String>();  

                List<WebElement> selectedOptions = new Select(driver.findElement(by))  

                                                                                .getAllSelectedOptions();  

                for(WebElement e : selectedOptions){  

                    set.add(e.getText());  

                }  

            return set.toArray(new String[set.size()]);  

        }  

  

        public String getSelectedLabel(By by) {  

            return getSelectedOption(by).getText();  

        }  

  

        public String[] getSelectedValues(By by) {  

            Set<String> set = new HashSet<String>();  

            List<WebElement> selectedOptions = new Select(driver.findElement(by))  

                                                                            .getAllSelectedOptions();  

            for(WebElement e : selectedOptions){  

                set.add(e.getAttribute("value"));  

            }  

        return set.toArray(new String[set.size()]);  

        }  

  

        public String getSelectedValue(By by) {  

            return getSelectedOption(by).getAttribute("value");  

        }  

  

        public String[] getSelectedIndexes(By by) {  

            Set<String> set = new HashSet<String>();  

            List<WebElement> selectedOptions = new Select(driver.findElement(by))  

                                                                            .getAllSelectedOptions();  

           List<WebElement> options = new Select(driver.findElement(by)).getOptions();  

            for(WebElement e : selectedOptions){  

                set.add(String.valueOf(options.indexOf(e)));  

            }  

            return set.toArray(new String[set.size()]);  

        }  

  

        public String getSelectedIndex(By by) {  

            List<WebElement> options = new Select(driver.findElement(by)).getOptions();  

            return String.valueOf(options.indexOf(getSelectedOption(by)));  

        }  

  

        public String[] getSelectedIds(By by) {  

            Set<String> ids = new HashSet<String>();  

            List<WebElement> options = new Select(driver.findElement(by)).getOptions();  

            for(WebElement option : options){  

                if(option.isSelected()) {  

                    ids.add(option.getAttribute("id")) ;  

                }  

            }  

            return ids.toArray(new String[ids.size()]);  

        }  

  

        public String getSelectedId(By by) {  

            return getSelectedOption(by).getAttribute("id");  

        }  

        private WebElement getSelectedOption(By by){  

            WebElement selectedOption = null;  

            List<WebElement> options = new Select(driver.findElement(by)).getOptions();  

            for(WebElement option : options){  

                if(option.isSelected()) {  

                    selectedOption = option;  

                }  

            }  

            return selectedOption;  

        }  

          

        public boolean isSomethingSelected(By by) {  

            boolean b = false;  

            List<WebElement> options = new Select(driver.findElement(by)).getOptions();  

            for(WebElement option : options){  

                if(option.isSelected()) {  

                    b = true ;  

                    break;  

                }  

            }  

            return b;  

        }  

  

        public String[] getSelectOptions(By by) {  

            Set<String> set = new HashSet<String>();  

            List<WebElement> options = new Select(driver.findElement(by)).getOptions();  

            for(WebElement e : options){  

                set.add(e.getText());  

            }  

        return set.toArray(new String[set.size()]);  

        }  

        public String getAttribute(By by,String attributeLocator) {  

            return driver.findElement(by).getAttribute(attributeLocator);  

        }  

  

        public boolean isTextPresent(String pattern) {  

            String Xpath= "http://*[contains(text(),\'"+pattern+"\')]" ;  

            try {   

                driver.findElement(By.xpath(Xpath));  

                return true;   

            } catch (NoSuchElementException e) {   

                return false;   

            }     

        }  

  

        public boolean isElementPresent(By by) {  

            return driver.findElements(by).size() > 0;  

        }  

  

        public boolean isVisible(By by) {  

            return driver.findElement(by).isDisplayed();  

        }  

  

        public boolean isEditable(By by) {  

            return driver.findElement(by).isEnabled();  

        }  

        public List<WebElement> getAllButtons() {  

            return driver.findElements(By.xpath("http://input[@type='button']"));              

        }  

  

        public List<WebElement> getAllLinks() {  

            return driver.findElements(By.tagName("a"));  

        }     

  

        public List<WebElement> getAllFields() {  

            return driver.findElements(By.xpath("http://input[@type='text']"));  

        }  

  

        public String[] getAttributeFromAllWindows(String attributeName) {  

            System.out.println("不知道怎么實現(xiàn)");  

            return null;  

        }  

        public void dragdrop(By by,String movementsString) {  

            dragAndDrop(by, movementsString);  

        }  

        public void dragAndDrop(By by,String movementsString) {  

            int index = movementsString.trim().indexOf('.');  

            int xOffset = Integer.parseInt(movementsString.substring(0, index));  

            int yOffset = Integer.parseInt(movementsString.substring(index+1));  

            new Actions(driver).clickAndHold(driver.findElement(by)).moveByOffset(xOffset, yOffset).perform();  

        }  

        public void setMouseSpeed(String pixels) {  

            System.out.println("不支持");  

        }  

  

        public Number getMouseSpeed() {  

            System.out.println("不支持");  

            return null;  

        }  

        public void dragAndDropToObject(By source,By target) {  

            new Actions(driver).dragAndDrop(driver.findElement(source), driver.findElement(target)).perform();  

        }  

  

        public void windowFocus() {  

            driver.switchTo().defaultContent();  

        }  

  

        public void windowMaximize() {  

            driver.manage().window().setPosition(new Point(0,0));  

            java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();  

            Dimension dim = new Dimension((int) screenSize.getWidth(), (int) screenSize.getHeight());  

            driver.manage().window().setSize(dim);  

        }  

  

        public String[] getAllWindowIds() {  

            System.out.println("不能實現(xiàn)敏沉!");  

            return null;  

        }  

  

        public String[] getAllWindowNames() {  

            System.out.println("不能實現(xiàn)果正!");  

            return null;  

        }  

  

        public String[] getAllWindowTitles() {  

            Set<String> handles = driver.getWindowHandles();  

            Set<String> titles = new HashSet<String>();  

            for(String handle : handles){  

                titles.add(driver.switchTo().window(handle).getTitle());  

            }  

            return titles.toArray(new String[titles.size()]);  

        }  

        public String getHtmlSource() {  

            return driver.getPageSource();  

        }  

  

        public void setCursorPosition(String locator,String position) {  

            System.out.println("沒能實現(xiàn)!");  

        }  

  

        public Number getElementIndex(String locator) {  

            System.out.println("沒能實現(xiàn)盟迟!");  

            return null;  

        }  

  

        public Object isOrdered(By by1,By by2) {  

            System.out.println("沒能實現(xiàn)秋泳!");  

            return null;  

        }  

  

        public Number getElementPositionLeft(By by) {  

            return driver.findElement(by).getLocation().getX();  

        }  

  

        public Number getElementPositionTop(By by) {  

            return driver.findElement(by).getLocation().getY();  

        }  

  

        public Number getElementWidth(By by) {  

            return driver.findElement(by).getSize().getWidth();  

        }  

  

        public Number getElementHeight(By by) {  

            return driver.findElement(by).getSize().getHeight();  

        }  

  

        public Number getCursorPosition(String locator) {  

            System.out.println("沒能實現(xiàn)!");  

            return null;  

        }  

  

        public String getExpression(String expression) {  

            System.out.println("沒能實現(xiàn)队萤!");  

            return null;  

        }  

  

        public Number getXpathCount(By xpath) {  

            return driver.findElements(xpath).size();  

        }  

  

        public void assignId(By by,String identifier) {  

            System.out.println("不想實現(xiàn)轮锥!");  

        }  

  

        /*public void allowNativeXpath(String allow) {  

            commandProcessor.doCommand("allowNativeXpath", new String[] {allow,});  

        }*/  

  

        /*public void ignoreAttributesWithoutValue(String ignore) { 

            commandProcessor.doCommand("ignoreAttributesWithoutValue", new String[] {ignore,}); 

             

        }*/  

  

        public void waitForCondition(String script,String timeout,Object... args) {  

            Boolean b = false;  

            int time = 0;  

            while(time <= Integer.parseInt(timeout)){  

                b = (Boolean) ((JavascriptExecutor)driver).executeScript(script,args);  

                if(b==true) break;  

                try {  

                    Thread.sleep(1000);  

                } catch (InterruptedException e) {  

                    // TODO Auto-generated catch block  

                    e.printStackTrace();  

                }  

                time += 1000;  

            }     

        }  

  

        public void setTimeout(String timeout) {  

            driver.manage().timeouts().implicitlyWait(Integer.parseInt(timeout), TimeUnit.SECONDS);  

        }  

  

        public void waitForPageToLoad(String timeout) {  

            driver.manage().timeouts().pageLoadTimeout(Integer.parseInt(timeout), TimeUnit.SECONDS);  

        }  

  

        public void waitForFrameToLoad(String frameAddress,String timeout) {  

            /*driver.switchTo().frame(frameAddress) 

                                .manage() 

                                .timeouts() 

                                .pageLoadTimeout(Integer.parseInt(timeout), TimeUnit.SECONDS);*/  

        }  

  

        public String getCookie() {  

            String cookies = "";  

            Set<Cookie> cookiesSet = driver.manage().getCookies();  

            for(Cookie c : cookiesSet){  

                cookies += c.getName()+"="+c.getValue()+";";  

                }  

            return cookies;  

        }  

  

        public String getCookieByName(String name) {  

            return driver.manage().getCookieNamed(name).getValue();  

        }  

  

        public boolean isCookiePresent(String name) {  

            boolean b = false ;  

            if(driver.manage().getCookieNamed(name) != null || driver.manage().getCookieNamed(name).equals(null))  

                b = true;  

            return b;  

        }  

  

        public void createCookie(Cookie c) {  

              

            driver.manage().addCookie(c);  

        }  

  

        public void deleteCookie(Cookie c) {  

            driver.manage().deleteCookie(c);  

        }  

  

        public void deleteAllVisibleCookies() {  

            driver.manage().getCookieNamed("fs").isSecure();  

        }  

  

        /*public void setBrowserLogLevel(String logLevel) { 

             

        }*/  

  

        /*public void runScript(String script) { 

            commandProcessor.doCommand("runScript", new String[] {script,}); 

        }*/  

  

        /*public void addLocationStrategy(String strategyName,String functionDefinition) { 

            commandProcessor.doCommand("addLocationStrategy", new String[] {strategyName,functionDefinition,}); 

        }*/  

  

        public void captureEntirePageScreenshot(String filename) {  

            File screenShotFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);  

            try {  

                FileUtils.copyFile(screenShotFile, new File(filename));  

            } catch (IOException e) {  

                // TODO Auto-generated catch block  

                e.printStackTrace();  

            }  

        }  

  

        /*public void rollup(String rollupName,String kwargs) { 

            commandProcessor.doCommand("rollup", new String[] {rollupName,kwargs,}); 

        } 

 

        public void addScript(String scriptContent,String scriptTagId) { 

            commandProcessor.doCommand("addScript", new String[] {scriptContent,scriptTagId,}); 

        } 

 

        public void removeScript(String scriptTagId) { 

            commandProcessor.doCommand("removeScript", new String[] {scriptTagId,}); 

        } 

 

        public void useXpathLibrary(String libraryName) { 

            commandProcessor.doCommand("useXpathLibrary", new String[] {libraryName,}); 

        } 

 

        public void setContext(String context) { 

            commandProcessor.doCommand("setContext", new String[] {context,}); 

        }*/  

  

        /*public void attachFile(String fieldLocator,String fileLocator) { 

            commandProcessor.doCommand("attachFile", new String[] {fieldLocator,fileLocator,}); 

        }*/  

  

        /*public void captureScreenshot(String filename) { 

            commandProcessor.doCommand("captureScreenshot", new String[] {filename,}); 

        }*/  

  

        public String captureScreenshotToString() {  

             String screen = ((TakesScreenshot)driver).getScreenshotAs(OutputType.BASE64);  

             return screen;  

        }  

  

       /* public String captureNetworkTraffic(String type) { 

            return commandProcessor.getString("captureNetworkTraffic", new String[] {type}); 

        } 

*/  

        /*public void addCustomRequestHeader(String key, String value) { 

            commandProcessor.getString("addCustomRequestHeader", new String[] {key, value}); 

        }*/  

  

        /*public String captureEntirePageScreenshotToString(String kwargs) { 

            return commandProcessor.getString("captureEntirePageScreenshotToString", new String[] {kwargs,}); 

        }*/  

  

        public void shutDown() {  

            driver.quit();  

        }  

  

        /*public String retrieveLastRemoteControlLogs() { 

            return commandProcessor.getString("retrieveLastRemoteControlLogs", new String[] {}); 

        }*/  

  

        public void keyDownNative(Keys keycode) {  

            new Actions(driver).keyDown(keycode).perform();  

        }  

  

        public void keyUpNative(Keys keycode) {  

            new Actions(driver).keyUp(keycode).perform();  

        }  

  

        public void keyPressNative(String keycode) {  

            new Actions(driver).click().perform();  

        }  

              

  

            public void waitForElementPresent(By by) {  

                for(int i=0; i<60; i++) {  

                if (isElementPresent(by)) {  

                break;  

                } else {  

                try {  

                driver.wait(1000);  

                } catch (InterruptedException e) {  

                e.printStackTrace();  

                        }  

                    }  

                }  

                }  

              

  

            public void clickAndWaitForElementPresent(By by, By waitElement) {  

                click(by);  

                waitForElementPresent(waitElement);  

                }  

       
            public Boolean VeryTitle(String exception,String actual){  

                if(exception.equals(actual)) return true;  

                else return false;  

            }  

        }  

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市要尔,隨后出現(xiàn)的幾起案子舍杜,更是在濱河造成了極大的恐慌,老刑警劉巖赵辕,帶你破解...
    沈念sama閱讀 218,284評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件既绩,死亡現(xiàn)場離奇詭異,居然都是意外死亡还惠,警方通過查閱死者的電腦和手機饲握,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,115評論 3 395
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來蚕键,“玉大人救欧,你說我怎么就攤上這事÷喙猓” “怎么了笆怠?”我有些...
    開封第一講書人閱讀 164,614評論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長誊爹。 經(jīng)常有香客問我蹬刷,道長瓢捉,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,671評論 1 293
  • 正文 為了忘掉前任办成,我火速辦了婚禮泡态,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘迂卢。我一直安慰自己某弦,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,699評論 6 392
  • 文/花漫 我一把揭開白布冷守。 她就那樣靜靜地躺著刀崖,像睡著了一般。 火紅的嫁衣襯著肌膚如雪拍摇。 梳的紋絲不亂的頭發(fā)上亮钦,一...
    開封第一講書人閱讀 51,562評論 1 305
  • 那天,我揣著相機與錄音充活,去河邊找鬼蜂莉。 笑死,一個胖子當(dāng)著我的面吹牛混卵,可吹牛的內(nèi)容都是我干的映穗。 我是一名探鬼主播,決...
    沈念sama閱讀 40,309評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼幕随,長吁一口氣:“原來是場噩夢啊……” “哼蚁滋!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起赘淮,我...
    開封第一講書人閱讀 39,223評論 0 276
  • 序言:老撾萬榮一對情侶失蹤辕录,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后梢卸,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體走诞,經(jīng)...
    沈念sama閱讀 45,668評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,859評論 3 336
  • 正文 我和宋清朗相戀三年蛤高,在試婚紗的時候發(fā)現(xiàn)自己被綠了蚣旱。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,981評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡戴陡,死狀恐怖塞绿,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情恤批,我是刑警寧澤异吻,帶...
    沈念sama閱讀 35,705評論 5 347
  • 正文 年R本政府宣布,位于F島的核電站开皿,受9級特大地震影響涧黄,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜赋荆,卻給世界環(huán)境...
    茶點故事閱讀 41,310評論 3 330
  • 文/蒙蒙 一笋妥、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧窄潭,春花似錦春宣、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,904評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至幽污,卻和暖如春嚷辅,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背距误。 一陣腳步聲響...
    開封第一講書人閱讀 33,023評論 1 270
  • 我被黑心中介騙來泰國打工簸搞, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人准潭。 一個月前我還...
    沈念sama閱讀 48,146評論 3 370
  • 正文 我出身青樓趁俊,卻偏偏與公主長得像,于是被迫代替她去往敵國和親刑然。 傳聞我的和親對象是個殘疾皇子寺擂,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,933評論 2 355

推薦閱讀更多精彩內(nèi)容