selenium從入門(mén)到精通-webdriver實(shí)用指南-java_第1頁(yè)
selenium從入門(mén)到精通-webdriver實(shí)用指南-java_第2頁(yè)
selenium從入門(mén)到精通-webdriver實(shí)用指南-java_第3頁(yè)
selenium從入門(mén)到精通-webdriver實(shí)用指南-java_第4頁(yè)
selenium從入門(mén)到精通-webdriver實(shí)用指南-java_第5頁(yè)
已閱讀5頁(yè),還剩51頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

titlesendkeysbuttonbuttonRemoteimportpublicclassStartBrowser{publicstaticvoidmain(String[]{WebDriverdr=new}}close方法關(guān)閉當(dāng)前的瀏覽器窗口,quit方法不僅關(guān)閉窗口,還會(huì)徹底的退出的close,quit會(huì)更好的釋放資源,適合強(qiáng)迫癥和完美主義者。importpublicclassCloseBrowser{publicstaticvoidmain(String[]{WebDriverdr=newChromeDriver();System.out.println("browserwillbeclosed");System.out.println("browseris}}importpublicclassize{publicstaticvoidmain(String[]args)throws{WebDriverdr=newChromeDriver();System.out.println("izebrowser");System.out.println("browserwillbeclose");}}sikuli操作flash;importpublicclassCloseBrowser{publicstaticvoidmain(String[]{WebDriverdr=newChromeDriver();System.out.println("browserwillbeclosed");System.out.println("browseris}}webdriver的api里有2種url的方式,分別是get和navigate.to方法。一般情況下建議使用get,因?yàn)槠渥帜副容^少,不太容易出錯(cuò)。importpublicclassGet{publicstaticvoidmain(String[]args)throws{WebDriverdr=newChromeDriver();Stringurl= System.out.printf("nowaccesss%s\n",url);System.out.println("browserwillbeclose");}}title測(cè)試中,1個(gè)頁(yè)面然后判斷其title是否符合預(yù)期是很常見(jiàn)的1個(gè)用例,所謂用例不夠,title1title是'oworld',那么可以寫(xiě)這樣的一個(gè)用例:該頁(yè)面,獲取該頁(yè)面的title,判斷獲取的值是否等于'oworld'。這時(shí)系統(tǒng)會(huì)自動(dòng)對(duì)這個(gè)url進(jìn)行跳轉(zhuǎn),這就是所謂的'重定向'。一般測(cè)試重定向urlurlimportpublicclassTitleAndUrl{publicstaticvoidmain(String[]args)throws{WebDriverdr=newChromeDriver();Stringurl="ht System.out.printf("nowaccesss%s\n",url);System.out.printf("titleofcurrentpageis%s\n",dr.getTitle());System.out.printf("urlofcurrentpageis%s\n",dr.getCurrentUrl());System.out.println("browserwillbeclose");}}回跳轉(zhuǎn),省去每次都geturl。importpublicclassForwardAndBack{publicstaticvoidmain(String[]args)throws{WebDriverdr=newChromeDriver();StringfirstUrl="ht System.out.printf("nowaccesss%s\n",firstUrl);StringsecondUrl="h System.out.printf("nowaccesss%s\n",secondUrl);System.out.printf("nowbackto%s\n",firstUrl);System.out.printf("forwardto%s\n",secondUrl);System.out.println("browserwillbeclose");}}class,nameclasslinkpartiallinktagcsshtml代碼<metahttp-equiv="content-type"content="text/html;charset=utf-8"<scripttype="text/javascript" href="/-bootstrap/2.3.2/css/bootbined.min.css"rel="stylesheet"/>src="/-bootstrap/2.3.2/js/bootst<h3>simplelogin<formclass="form-<divclass="control-<labelclass="control-label"for="input"><div<inputtype="text"id="input"placeholder=""name="<divclass="control-<labelclass="control-label"<div<inputtype="password"id="inputPassword"placeholder="Password"<divclass="control-<div<label<inputtype="checkbox">Remember<buttontype="submit"class="btn">Sign<ajava代碼importimportimportorg.openqa.selenium.WebDriver;importimportorg.openqa.selenium.JavascriptExecutor;publicclassSimpleLocate{publicstaticvoidmain(String[]args)throwsInterruptedExceptionWebDriverdr=newChromeDriver();Filefile=newFile("src/form.html");StringfilePath="file:///"+file.getAbsolutePath();System.out.printf("nowaccesss%s\n",filePath);//byid//byname//byStringclassOfForm=System.out.printf("%s\n",classOfForm);//bylinkWebElementlink=dr.findElement(By.linkText("register"));eIn()",link);//bypartiallinkWebElementsameLink=dr.findElement(By.partialLinkText("reg"));eIn()",sameLink);//bycssWebElementdiv=dr.findElement(By.cssSelector(".controls"));eIn()",div);//byxpathSystem.out.println("browserwillbeclose");}}上面例子里由于html文件中了jquery,所以在執(zhí)行js時(shí)可以使用jquery的$fadeIn(jquery從上一節(jié)的例子中可以看出,webdriver可以很方便的使用findElement方法用findElements方法。定位出頁(yè)面上所有的checkbox,然后選擇最后一個(gè)<metahttp-equiv="content-type"content="text/html;charset=utf-8"<scripttype="text/javascript" href="/-bootstrap/2.3.2/css/bootbined.min.css"rel="stylesheet"/>src="/-bootstrap/2.3.2/js/bootst<div<formclass="form-<divclass="control-<labelclass="control-label"<div<inputtype="checkbox"id="c1"<divclass="control-<labelclass="control-label"<div<inputtype="checkbox"id="c2"<divclass="control-<labelclass="control-label"<div<inputtype="checkbox"id="c3"<divclass="control-<labelclass="control-label"<div<inputtype="radio"id="r"importimportimportimportorg.openqa.selenium.WebDriver;importimportorg.openqa.selenium.JavascriptExecutor;publicclassSimpleLocate{publicstaticvoidmain(String[]args)throws{WebDriverdr=newFilefile=newStringfilePath="file:///"+file.getAbsolutePath();System.out.printf("nowaccesss%s\n",filePath);List<WebElement>checkboxes=for(WebElementcheckbox:checkboxes){}//打印當(dāng)前頁(yè)面上有多少個(gè)checkboxList<WebElement>inputsdr.findElements(By.tagName("input"));for(WebElementinput:}}List<WebElement>allCheckboxes=allCheckboxes.get(allCheckboxes.size()-1).click();System.out.println("browserwillbeclose");}}checkbox.html必須與find_elments.rb在同一 linktext,hrefullink1Anotheraction這個(gè)選項(xiàng)。<metahttp-equiv="content-type"content="text/html;charset=utf-8"<title>Level<scripttype="text/javascript" href="/-bootstrap/2.3.2/css/bootbined.min.css"rel="stylesheet"/><h3>Level<div<div<div<aclass="dropdown-toggle"data-toggle="dropdown"<ulclass="dropdown- "role=" "aria-labelledby="dLabel"id="dropdown1"><li><atabindex="-1"<li><atabindex="-1"href="#">Another<li><atabindex="-1"href="#">Somethingelse<li<li><atabindex="-1"href="#">Separated<div<div<div<aclass="dropdown-toggle"data-toggle="dropdown"<ul " "aria-labelledby="dLabel"<li><atabindex="-1"<li><atabindex="-1"href="#">Another<li><atabindex="-1"href="#">Somethingelse<li<li><atabindex="-1"href="#">Separatedsrc="/-bootstrap/2.3.2/js/bootstimportimportorg.openqa.selenium.By;importimportorg.openqa.selenium.chrome.ChromeDriver;importimportorg.openqa.selenium.support.ui.WebDriverWait;publicclassLevelLocate{publicstaticvoidmain(String[]args)throws{WebDriverdr=newFilefile=newStringfilePath="file:///"+file.getAbsolutePath();System.out.printf("nowaccesss%s\n",filePath);(newWebDriverWait(dr,10)).until(newExpectedCondition<Boolean>(){publicBooleanapply(WebDriverd){returnd.findElement(By.id("dropdown1")).isDisplayed();}} (newActions(dr)).moveToElement( System.out.println("browserwillbeclose");}}click點(diǎn)擊對(duì)象sendKeysclear<metahttp-equiv="content-type"content="text/html;charset=utf-8"<title>Level<scripttype="text/javascript" href="/-bootstrap/2.3.2/css/bootbined.min.css"rel="stylesheet"/><h3>Level<div<div<div<aclass="dropdown-toggle"data-toggle="dropdown"<ulclass="dropdown-"role=""aria-labelledby="dLabel"id="dropdown1"><li><atabindex="-1"<li><atabindex="-1"href="#">Another<li><atabindex="-1"href="#">Somethingelse<li<li><atabindex="-1"href="#">Separated<div<div<div<aclass="dropdown-toggle"data-toggle="dropdown"<ul " "aria-labelledby="dLabel"<li><atabindex="-1"<li><atabindex="-1"href="#">Another<li><atabindex="-1"href="#">Somethingelse<li<li><atabindex="-1"href="#">Separatedsrc="/-bootstrap/2.3.2/js/bootstimportimportimportorg.openqa.selenium.WebDriver;importpublicclassOperateElement{publicstaticvoidmain(String[]args)throws{WebDriverdr=newFilefile=newFile("src/operate_element.html");StringfilePath="file:///"+file.getAbsolutePath();System.out.printf("nowaccesss%s\n",filePath);//click//WebElementelement=dr.findElement(B("q"));//clearSystem.out.println("browserwillbeclose");}}sendkeys<metahttp-equiv="content-type"content="text/html;charset=utf-8"<title>send<scripttype="text/javascript" href="/-bootstrap/2.3.2/css/bootbined.min.css"rel="stylesheet"/><h3>send<divclass="row-<div<div<textarearows="10",cols="10"id="A">Ithinkwatir-webdriverisbetterthanselenium-webdriver</textarea><div<div<textarearows="10",cols="10"src="/-bootstrap/2.3.2/js/bootstimportimportorg.openqa.selenium.By;importorg.openqa.selenium.Keys;publicclassSendKeys{publicstaticvoidmain(String[]args)throws{WebDriverdr=newFilefile=newStringfilePath="file:///"+file.getAbsolutePath();System.out.printf("nowaccesss%s\n",filePath);//copycontentofdr.findElement(By.id("A")).sendKeys(Keys.chord(Keys.CONTROL+"a"));dr.findElement(By.id("A")).sendKeys(Keys.chord(Keys.CONTROL+"x"));//pastetoBdr.findElement(By.id("B")).sendKeys(Keys.chord(Keys.CONTROL+"v"));//SendKeystoAdr.findElement(By.id("A")).sendKeys(Keys.chord("watirwebdriverisbetterthanseleniumwebdriver"));System.out.println("browserwillbeclose");}}是先找到buttongroup的包裹(wrapper)div,然后通過(guò)層級(jí)定位,用index下面的代碼演示了如何找到second這個(gè)按鈕。其處理方法是先找到buttongroupdiv,classbtn-groupdivdiv(也就是button),返回text是second的div。<metahttp-equiv="content-type"content="text/html;charset=utf-8"<title>button<scripttype="text/javascript" href="/-bootstrap/2.3.2/css/bootbined.min.css"rel="stylesheet"/><script$(<h3>button<divclass="row-<div<div<divclass="btn-<divclass="btn-<div<div<divsrc="/-bootstrap/2.3.2/js/bootstimportjava.io.File;importorg.openqa.selenium.By;importorg.openqa.selenium.WebDriver;importpublicclassButtonGroup{publicstaticvoidmain(String[]args)throws{WebDriverdr=newFilefile=newStringfilePath="file:///"+file.getAbsolutePath();System.out.printf("nowaccesss%s\n",filePath);List<WebElement>btnsfor(WebElementbtn}}System.out.println("browserwillbeclose");}}buttonlinktext為watir-webdriver的link,并點(diǎn)擊之。<metahttp-equiv="content-type"content="text/html;charset=utf-8"<title>button<scripttype="text/javascript" href="/-bootstrap/2.3.2/css/bootbined.min.css"rel="stylesheet"/><script$(<h3>button<divclass="row-<div<div<divclass="btn-<divclass="btn-<div<div<divsrc="/-bootstrap/2.3.2/js/bootstimportimportorg.openqa.selenium.By;importimportorg.openqa.selenium.support.ui.WebDriverWait;publicclassButtonDropdown{publicstaticvoidmain(String[]args)throws{WebDriverdr=newFilefile=newFile("src/button_dropdown.html");StringfilePath="file:///"+file.getAbsolutePath();System.out.printf("nowaccesss%s\n",filePath);(newWebDriverWait(dr,10)).until(new{publicBooleanapply(WebDriverreturn } System.out.println("browserwillbeclose");}}ullilink基本就能解決問(wèn)題。代<metahttp-equiv="content-type"content="text/html;charset=utf-8"<scripttype="text/javascript" href="/-bootstrap/2.3.2/css/bootbined.min.css"rel="stylesheet"/><script$().ready($('.nav').find('li').click(function()}<divclass="row-<div<ulclass="navnav-<li<a<li><a<li><asrc="/-bootstrap/2.3.2/js/bootstimportjava.io.File;importorg.openqa.selenium.By;importorg.openqa.selenium.WebDriver;importpublicclassNavs{publicstaticvoidmain(String[]args)throws{WebDriverdr=newChromeDriver();Filefile=newFile("src/navs.html");StringfilePath="file:///"+file.getAbsolutePath();System.out.printf("nowaccesss%s\n",filePath);//方法1:層級(jí)定位,先定位ulli//方法2:直接定位linkSystem.out.println("browserwillbeclose");}}代<metahttp-equiv="content-type"content="text/html;charset=utf-8"<scripttype="text/javascript" href="/ bined.min.css"rel="stylesheet"/><script$().ready(}<divclass="row-<div<ul<li><ahref="#">Home</a><span<li><ahref="#">Library</a><span<lisrc="/-bootstrap/2.3.2/js/bootstimportjava.io.File;importimportorg.openqa.selenium.WebDriver;importpublicclassBreadcrumb{publicstaticvoidmain(String[]args)throwsInterruptedExceptionWebDriverdr=newFilefile=newStringfilePath="file:///"+file.getAbsolutePath();System.out.printf("nowaccesss%s\n",filePath);List<WebElement>ancestors=for(WebElementlinkancestors){}WebElementcurrent=System.out.println("browserwillbeclose");}}處處框場(chǎng)框是一個(gè)iframe,處理起來(lái)有點(diǎn)麻煩,需要進(jìn)行switch_to處理框一般會(huì)做下面的一些事情打開(kāi)關(guān)閉<metahttp-equiv="content-type"content="text/html;charset=utf-8"<scripttype="text/javascript" href="/ bined.min.css"rel="stylesheet"/><script$($(this).parent().find('p').text('trywatir-webdriverright<divclass="row-<div<!--Buttontotriggermodal--<ahref="#myModal"role="button"class="btnbtn-primary"data-toggle="modal"id="show_modal">Click</a><!--Modal--<divid="myModal"class="modalhidefade"tabindex="-1"role="dialog"aria-labelledby="myModalLabel"aria-hidden="true"><divclass="modal-<buttontype="button"class="close"data-dismiss="modal"<h3id="myModalLabel">Modal<divclass="modal-<p>watir-webdriverisbetterthanslenium-<ahref="#"id="click">click<divclass="modal-<buttonclass="btn"data-dismiss="modal"<buttonclass="btnbtn-primary">Savesrc="/-bootstrap/2.3.2/js/bootstimportjava.io.File;importimportorg.openqa.selenium.Keys;importorg.openqa.selenium.WebDriver;importimportimportorg.openqa.selenium.support.ui.WebDriverWait;publicclassModal{publicstaticvoidmain(String[]args)throws{WebDriverdr=newChromeDriver();Filefile=newFile("src/modal.html");StringfilePath="file:///"+file.getAbsolutePath();System.out.printf("nowaccesss%s\n",filePath);//打開(kāi)框(newWebDriverWait(dr,10)).until(new{publicBooleanapply(WebDriver{return}}//點(diǎn) 框中的//由于 clickable的錯(cuò)誤//在watir-webdriver中只需要fire_event(:click)就可以了WebElementlink=System.out.println("browserwillbeclose");}}法可以獲取dom元素(測(cè)試對(duì)象)的屬性。中,使用element.getText()方法可以返回dom節(jié)點(diǎn)的內(nèi)容(text)。代<metahttp-equiv="content-type"content="text/html;charset=utf-8"<scripttype="text/javascript" href="/-bootstrap/2.3.2/css/bootbined.min.css"rel="stylesheet"/><script$($('#tooltip').tooltip({"placement":<divclass="row-<div<aid="tooltip"href="#"data-toggle="tooltip"title="watir-webdriverbetterthanselenium-webdriver">hovertoseetooltip</a>src="/-bootstrap/2.3.2/js/bootstimportjava.io.File;importjava.util.List;importimportorg.openqa.selenium.WebDriver;importpublicclassAttribute{publicstaticvoidmain(String[]args)throws{WebDriverdr=newFilefile=newStringfilePath="file:///"+file.getAbsolutePath();System.out.printf("nowaccesss%s\n",filePath);WebElementlink=tooltip//獲取該的textSystem.out.println("browserwillbeclose");}}當(dāng)你的測(cè)試用例糾結(jié)需要通過(guò)判斷元素的css屬性來(lái)驗(yàn)證你定的就是css了,css變動(dòng)頻繁,而且通過(guò)屬性也不能直觀的判斷頁(yè)面的顯示效果,代<metahttp-equiv="content-type"content="text/html;charset=utf-8"<scripttype="text/javascript" href="/-bootstrap/2.3.2/css/bootbined.min.css"rel="stylesheet"/><script$($('#tooltip').tooltip({"placement":<divclass="row-<div<aid="tooltip"href="#"data-toggle="tooltip"title="watir-webdriverbetterthanselenium-webdriver">hovertoseetooltip</a>src="/-bootstrap/2.3.2/js/bootstimportimportimportimportorg.openqa.selenium.WebDriver;importpublicclassCss{publicstaticvoidmain(String[]args)throws{WebDriverdr=newChromeDriver();Filefile=newFile("src/css.html");StringfilePath="file:///"+file.getAbsolutePath();System.out.printf("nowaccesss%s\n",filePath);WebElementlink=dr.findElement(By.id("tooltip"));System.out.println("browserwillbeclose");}}使用element.isSelected()方法;<metahttp-equiv="content-type"content="text/html;charset=utf-8"<scripttype="text/javascript" href="/ bined.min.css"rel="stylesheet"/><script$($('#tooltip').tooltip({"placement":<divclass="row-<div<inputname="user"placeholder="DisabledTextField"disabled<div<aclass="btndisabled">Disabled<div<inputname="radio"type="radio"src="/-bootstrap/2.3.2/js/bootstimportjava.io.File;importimportorg.openqa.selenium.JavascriptExecutor;importorg.openqa.selenium.WebDriver;importpublicclassStatus{publicstaticvoidmain(String[]args)throws{WebDriverdr=newFilefile=newStringfilePath="file:///"+file.getAbsolutePath();System.out.printf("nowaccesss%s\n",filePath);WebElementtextField=dr.findElement(B("user"));//判斷其是否顯示W(wǎng)ebElementradio=dr.findElement(B("radio"));try{}e){System.out.println("elementdoesnot}System.out.println("browserwillbeclose");}}討在這里我們遇到了一種情況,那就是測(cè)試對(duì)象看上去是disabled,但是使用通過(guò)這些值去進(jìn)一步判斷對(duì)象是否disable。<metahttp-equiv="content-type"content="text/html;charset=utf-8"<scripttype="text/javascript" href="/-bootstrap/2.3.2/css/bootbined.min.css"rel="stylesheet"/><script$(alert('watir-webdriverisbetterthanselenium<divclass="row-<divclass="span6<label<inputtype="checkbox">Checkme<label<inputtype="radio">select<label</select>selectone<inputtype="submit"class="btn"value="submit"src="/-bootstrap/2.3.2/js/bootstimportjava.io.File;importorg.openqa.selenium.By;importorg.openqa.selenium.Keys;importorg.openqa.selenium.WebDriver;importpublicclassForm{publicstaticvoidmain(String[]args)throws{WebDriverdr=newChromeDriver();Filefile=newFile("src/form.html");StringfilePath="file:///"+file.getAbsolutePath();System.out.printf("nowaccesss%s\n",filePath);//選中checkbox//選中radioList<WebElement>options=options.get(options.size()-1).click();//點(diǎn)擊提交按鈕Alertalert=dr.switchTo().alert();System.out.println("browserwillbeclose");}}代<metahttp-equiv="content-type"content="text/html;charset=utf-8"<scripttype="text/javascript" href="/-bootstrap/2.3.2/css/bootbined.min.css"rel="stylesheet"/><script$($('#tooltip').tooltip({"placement":<divclass="row-<divclass="span6<aid="tooltip"href="#"data-toggle="tooltip"title="watir-webdriverbetterthanselenium-webdriver">hovertoseetooltip</a><asrc="/-bootstrap/2.3.2/js/bootstimportjava.io.File;importorg.openqa.selenium.By;importorg.openqa.selenium.Keys;importorg.openqa.selenium.WebDriver;importpublicclassJs{publicstaticvoidmain(String[]args)throws{WebDriverdr=newChromeDriver();Filefile=newStringfilePath="file:///"+file.getAbsolutePath();System.out.printf("nowaccesss%s\n",filePath);//在頁(yè)面上直接執(zhí)行jsWebElementbutton=dr.findElement(By.className("btn"));System.out.println("browserwillbeclose");}}是使用switch_to.alert()方法定位到alert/confirm/prompt。然后使用text/accept/dismiss/send_keys按需進(jìn)行操做<metahttp-equiv="content-type"content="text/html;charset=utf-8"<scripttype="text/javascript" href="/-bootstrap/2.3.2/css/bootbined.min.css"rel="stylesheet"/><script$($('#tooltip').tooltip({"placement":alert('watir-webdriverbetterthanselenium-<divclass="row-<divclass="span6<aid="tooltip"href="#"data-toggle="tooltip"title="watir-webdriverbetterthanselenium-webdriver">hovertoseetooltip</a>src="/-bootstrap/2.3.2/js/bootstimportjava.io.File;importorg.openqa.selenium.By;importorg.openqa.selenium.Keys;importorg.openqa.selenium.WebDriver;importpublicclassAlertExample{publicstaticvoidmain(String[]args)throws{WebDriverdr=newChromeDriver();Filefile=newFile("src/alert.html");StringfilePath="file:///"+file.getAbsolutePath();System.out.printf("nowaccesss%s\n",filePath);//點(diǎn)擊彈出alertAlertalert=dr.switchTo().alert();System.out.println("browserwillbeclose");}}場(chǎng)的操作。另外頁(yè)面加載時(shí)有可能會(huì)執(zhí)行一些ajax,這時(shí)候也需要去WebDriverWaituntilajax的請(qǐng)求執(zhí)行完畢。publicWebDriverWait(WebDriverdriver,longpublicWebDriverWait(WebDriverdriver,longtimeOutInSeconds,longsleepInMillis)WebDriverdriverlongtimeOutInSeconds另外要注意的是,默認(rèn)情況下,unitl中的NotFoundException會(huì)被忽略,但是其他異常還是正常的。你可以通過(guò)ignoring(exceptionstoadd)自己定義需代下面代碼演示了點(diǎn)擊按鈕后如何等待label這個(gè)例子其實(shí)沒(méi)有前面的下拉菜<metahttp-equiv="content-type"content="text/html;charset=utf-8"<scripttype="text/javascript" href="/-bootstrap/2.3.2/css/bootbined.min.css"rel="stylesheet"/><script$($('<p><span<divclass="row-<divclass="span6<buttonclass="btnbtn-primary"id="btn"src="/-bootstrap/2.3.2/js/bootstimportjava.io.File;importorg.openqa.selenium.By;importorg.openqa.selenium.Keys;importorg.openqa.selenium.WebDriver;importimportimportorg.openqa.selenium.support.ui.WebDriverWait;publicclassWaitExample{publicstaticvoidmain(String[]args)throws{WebDriverdr=newChromeDriver();Filefile=newFile("src/wait.html");StringfilePath="file:///"+file.getAbsolutePath();System.out.printf("nowaccesss%s\n",filePath);(newWebDriverWait(dr,10)).until(new{publicBooleanapply(WebDriverd)return}System.out.println("browserwillbeclose");}}switchTo.defaultContent()WebElement,frameStringid,frame我們可以從frame的實(shí)質(zhì)去理解。frame中實(shí)際上是嵌入了另一個(gè)頁(yè)面,而webdriverswitch_to.frame取frame中嵌入的頁(yè)面,對(duì)那個(gè)頁(yè)面里的元素進(jìn)行定位。代碼的frame,該frame加載了的首頁(yè)<metahttp-equiv="content-type"content="text/html;charset=utf-8"<scripttype="text/javascript" href="/ bined.min.css"rel="stylesheet"/><script$(<divclass="row-<divclass="span10<iframeid="f1"src="inner.html"width="800",src="/-bootstrap/2.3.2/js/bootst<metahttp-equiv="content-type"content="text/html;charset=utf-8"<divclass="row-<divclass="span6<iframeid="f2"src="ht "width="700"<ahref="javascript:alert('watir-webdriverbetterthanseleniumimportjava.io.File;importorg.openqa.selenium.By;importorg.openqa.selenium.Keys;importorg.openqa.selenium.WebDriver;importimportimportorg.openqa.selenium.support.ui.WebDriverWait;publicclassFrame{publicstaticvoidmain(String[]args)throws{WebDriverdr=newChromeDriver();Filefile=newFile("src/frame.html");StringfilePath="file:///"+file.getAbsolutePath();System.out.printf("nowaccesss%s\n",filePath);//先到f1再到f2//往f2中的關(guān)鍵字文本框中輸入內(nèi)容//直接跳出所有frame//再到f1System.out.println("browserwillbeclose");}}討假設(shè)頁(yè)A、Bframe,BA內(nèi),那么定B中的內(nèi)容則需要先你完全可以提出1個(gè)頁(yè)面前端性能的缺陷;時(shí)放棄跟此frame相關(guān)的用例才是明智之舉;場(chǎng)contextClickActionsaction=newActions(driver)討代<metahttp-equiv="content-type"content="text/html;charset=utf-8"<scripttype="text/javascript" href="/-bootstrap/2.3.2/css/bootbined.min.css"rel=

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論