![selenium常用的方法_第1頁(yè)](http://file1.renrendoc.com/fileroot_temp2/2020-12/14/d94d8450-1243-4035-b49e-ebee4b4bda99/d94d8450-1243-4035-b49e-ebee4b4bda991.gif)
![selenium常用的方法_第2頁(yè)](http://file1.renrendoc.com/fileroot_temp2/2020-12/14/d94d8450-1243-4035-b49e-ebee4b4bda99/d94d8450-1243-4035-b49e-ebee4b4bda992.gif)
![selenium常用的方法_第3頁(yè)](http://file1.renrendoc.com/fileroot_temp2/2020-12/14/d94d8450-1243-4035-b49e-ebee4b4bda99/d94d8450-1243-4035-b49e-ebee4b4bda993.gif)
![selenium常用的方法_第4頁(yè)](http://file1.renrendoc.com/fileroot_temp2/2020-12/14/d94d8450-1243-4035-b49e-ebee4b4bda99/d94d8450-1243-4035-b49e-ebee4b4bda994.gif)
![selenium常用的方法_第5頁(yè)](http://file1.renrendoc.com/fileroot_temp2/2020-12/14/d94d8450-1243-4035-b49e-ebee4b4bda99/d94d8450-1243-4035-b49e-ebee4b4bda995.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、package avaya.browser.method;import java.io.IOException;import java.util.*;import org.junit.Before;import org.openqa.*;import com.thoughtworks.selenium.Wait;import erfac.Driver;/attention: 以Br.開頭的方法,是因?yàn)锽r是自己在本類還封裝了一層,需要仔細(xì)看代碼public class Br extends Baseclass private String locator;pu
2、blic static String log(String info)System.out.println(info);return info;public static void openbrowser(String url)/driver=new FirefoxDriver();/Navigation navitation=driver.navigate();/navitation.to(url);driver.get(url);Br.log(open browser and input testURL:+url);/opration the windows maxpublic stati
3、c void maxwindow()driver.manage().window().maximize();Br.log(max windows);/refresh the windowspublic static void refresh()driver.navigate().refresh();Br.log(refresh the windows); public static void login(String url,String user,String pwd) throws InterruptedException driver.get(url); Br.clear(By.id(B
4、r.logrm:username); Br.sendkeys(By.id(Br.logrm:username),user); Br.clear(By.id(Br.logrm:password); Br.sendkeys(By.id(Br.logrm:password),pwd); Br.getWebText(By.id(Br.logrm:submitText); driver.findElement(By.id(Br.logrm:submitText).click(); try Thread.sleep(5000); catch (InterruptedException e) / TODO
5、Auto-generated catch blocke.printStackTrace(); Op.refresh();Br.log(,input:+url);Br.log(登陸賬號(hào)為:+user+ +登陸密碼為:+pwd); /if form parameter is not null,input data and use this method;public static void closebrowser(String BrowserType)if(BrowserType!=null) if(BrowserType.equals(c) try Runtime.getRuntime().e
6、xec(taskkill /F /IM chrome.exe); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace(); else if(BrowserType.equals(i) try Runtime.getRuntime().exec(taskkill /F /IM iexplorer.exe); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace(); else if(BrowserType.equ
7、als(o) try Runtime.getRuntime().exec(taskkill /F /IM opera.exe); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace(); else if(BrowserType.equals(s) try Runtime.getRuntime().exec(taskkill /F /IM safari.exe); catch (IOException e) / TODO Auto-generated catch block e.printStackTr
8、ace(); else try Runtime.getRuntime().exec(taskkill /F /IM firefox.exe); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace(); /if form parameter is null,use this method;public static void closebrowser()try Runtime.getRuntime().exec(taskkill /F /IM firefox.exe); catch (IOExcepti
9、on e) / TODO Auto-generated catch blocke.printStackTrace(); public static void switchToIframe(By by)driver.switchTo().frame(driver.findElement(by);/driver.switchTo().frame(driver.findElement(By.xpath(/html/body/div4/div4/div/div/iframe); /find element and set the valuepublic static void sendkeys(By
10、by,String str) throws InterruptedExceptionString text;/text=driver.findElement(by).getText();driver.findElement(by).clear();Thread.sleep(1500);driver.findElement(by).sendKeys(str);/Br.log(execute select element object+text);Br.log(Set: +str);public static void click(By by) throws InterruptedExceptio
11、nString text;if(driver.findElement(by).getText()!=null & ! .equals(driver.findElement(by).getText()text=driver.findElement(by).getText();Thread.sleep(3000);System.out.println(execute click operation);System.out.println(click+ +text);elseSystem.out.println(this Element is not found text);driver.findE
12、lement(by).click();/* doubleclick * by */public static void doubleClick(By by)new Actions(driver).doubleClick(driver.findElement(by).doubleClick();public static void clear(By by)driver.findElement(by).clear();Br.log(Empty element content,by: +by);/*select element by index * webdriver is nonsupport s
13、elect function,so suggest not */ public static void selectByIndex(By by,int index)/driver.findElement(by).click();String text;Select select=new Select(driver.findElement(by);try Thread.sleep(10); catch (InterruptedException e) / TODO Auto-generated catch blocke.printStackTrace();select.selectByIndex
14、(index);Br.log(Perform a drop-down box operations,operation element:+by);text=getWebText(by);Br.log(select+index+element+element info is:+text);/*select element by value * webdriver is nonsupport select function,so suggest not */public static void selectByText(By by,String text)driver.findElement(by
15、).click();Select select=new Select(driver.findElement(by);select.selectByVisibleText(text);/select element by value/public static void selectBy(By by,String value)/driver.findElement(by).click();/Select select=new Select(driver.findElement(by);/select.selectByValue(value);/public static void select(
16、By by0,By by1)/driver.findElement(by0).click();/driver.findElement(by1).click();/Select select=new Select(driver.findElement(by);/select.selectByValue(value);/*select element by linktext * webdriver is nonsupport select function,so suggest not */public static void selectByLinkText(By by,String LinkT
17、ext)/driver.findElement(by).click();Select select=new Select(driver.findElement(by);select.selectByValue(LinkText);Br.log(execute select element ,the object:+LinkText); / 獲取鏈接元素的url值 public static String getLinkUrl(By by) return driver.findElement(by).getAttribute(href); / 判斷某個(gè)元素是否存在 public static b
18、oolean isElementExist(By by) try Boolean bool = driver.findElement(by).isDisplayed(); Br.log(execute+by+exist or not+,+result is :+bool); return bool; catch(NoSuchElementException e) return false; / 獲得某元素的文本描述信息 public static String getWebText(By by) String text; text=driver.findElement(by).getText(
19、);try Br.log(get Element text +:+text);return text;/return driver.findElement(by).getText();catch (NoSuchElementException e)return not found the Element text!; /* * 在一個(gè)元素集合中通過遍歷文本內(nèi)容定位到相應(yīng)的元素 */ public static void clickElementContainingText(By by,String text) List elementList = driver.findElements(by)
20、; for(WebElement e:elementList) if(e.getText().contains(text) e.click(); break; /* 根據(jù)id定位元素并獲取元素的選中狀態(tài) * param id * return */ public static boolean getselectstat(By by) boolean flag=true; if(flag) Br.log(頁(yè)面元素狀態(tài):+by+已被選中); return driver.findElement(by).isSelected(); else Br.log(頁(yè)面元素狀態(tài):+by+未被選中); retur
21、n false; /* 等待時(shí)間 * param second * return */ public static boolean wait(int second) trydriver.manage().timeouts().implicitlyWait(second, TimeUnit.SECONDS); /Br.log(執(zhí)行了等待操作,等待了+second+秒); return true; catch(Exception e) return false; / public static void waitForpageToload(int i)/ boolean isLoaded=fals
22、e; / int count=0; / do / if(count+3) / break; / / try / selenium.waitForPageToLoad(i); / isLoaded=true; / catch(Exception ex) / continue; / / while(!isLoaded); / / / /public boolean switchToWindow(WebDriver driver,String windowTitle) / 通過彈出框的title進(jìn)行切換,非xpath等方法,此方法比較方便 public static boolean switchto
23、bytitle(String windowTitle) boolean flag = false; try String currentHandle = driver.getWindowHandle(); Set handles = driver.getWindowHandles(); for (String s : handles) if (s.equals(currentHandle) /System.out.println(test here); continue; else driver.switchTo().window(s); if (driver.getTitle().contains(windowTitle) flag = true; System.out.println(切換窗口到:+ windowTitle); break; else continue; catch (NoSuchWindowException e) System.out.printf(Window: + windowTitle+ cound not found!, e.fillInStackTrace(); flag = false; return flag; /* 通過windows的id號(hào)進(jìn)行切換 * i 窗口的索引從0開始 * by driver的查找元素
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年全球及中國(guó)運(yùn)動(dòng)刺激療法行業(yè)頭部企業(yè)市場(chǎng)占有率及排名調(diào)研報(bào)告
- 2025年全球及中國(guó)鋼制螺旋錐齒輪行業(yè)頭部企業(yè)市場(chǎng)占有率及排名調(diào)研報(bào)告
- 2025年全球及中國(guó)戶外電氣箱行業(yè)頭部企業(yè)市場(chǎng)占有率及排名調(diào)研報(bào)告
- 2025-2030全球軸承精密滾珠行業(yè)調(diào)研及趨勢(shì)分析報(bào)告
- 2025年全球及中國(guó)QUV紫外老化試驗(yàn)箱行業(yè)頭部企業(yè)市場(chǎng)占有率及排名調(diào)研報(bào)告
- 2025房地產(chǎn)公司辦公區(qū)空調(diào)安裝合同
- 理療店項(xiàng)目合作合同范本
- 委托的貨物運(yùn)輸合同范本
- 鋼板租賃合同書
- 干股協(xié)議書范本合同
- 蛋糕店服務(wù)員勞動(dòng)合同
- 土地買賣合同參考模板
- 2025高考數(shù)學(xué)二輪復(fù)習(xí)-專題一-微專題10-同構(gòu)函數(shù)問題-專項(xiàng)訓(xùn)練【含答案】
- 2025年天津市政建設(shè)集團(tuán)招聘筆試參考題庫(kù)含答案解析
- 2024-2030年中國(guó)烘焙食品行業(yè)運(yùn)營(yíng)效益及營(yíng)銷前景預(yù)測(cè)報(bào)告
- 寧德時(shí)代筆試題庫(kù)
- 康復(fù)醫(yī)院患者隱私保護(hù)管理制度
- 新課標(biāo)I、Ⅱ卷 (2024-2020) 近五年高考英語(yǔ)真題滿分作文
- 公司安全事故隱患內(nèi)部舉報(bào)、報(bào)告獎(jiǎng)勵(lì)制度
- 沈陽(yáng)理工大學(xué)《數(shù)》2022-2023學(xué)年第一學(xué)期期末試卷
- 共享單車安全知識(shí)
評(píng)論
0/150
提交評(píng)論