The focus of this section
Working with Drop-down boxes
Switch_to_alert ()
Accept ()
Dropdown box is our most common kind of page elements, for the general element, we only need to position once, but the contents of the dropdown box needs to be positioned two times, first navigate to the Drop-down box, and then navigate to the dropdown box in the options.
Drop_down.html
Saving the above code to HTML opens with a browser to see the simplest common drop-down box, with several options for the
Selenium provides many API methods to interact with the page, such as click, keyboard input, turn off Web pages, enter text, and more.Webdriver provides many properties to the browser to operate the browser, commonly usedGet (URL), quit () Maximize_window () Current_urlBack () forward () Current_window_handle and window_handles To open Baidu Home-----Point of registration, to register also registered------then go to the login page login as an exampl
JS dialogs such as alert, confirm, and prompt can be easily and concisely processed in selenium webdriveriver. The following HTML code is used as an example:
Example.html
Content '); document. Write (name) "/>
The preceding HTML code displays three buttons on the page. Click them to bring up the alert, confirm, and prompt dialog boxes. If you enter the text in the prompt dialog box and click OK, the page is refreshed to display the text.
Since the launch of the Selenium+webdriver, the learning UI level of automated testing has a lot of convenience, learning curve and difficulty are reduced, at least the introduction is relatively simple, basically understand the point of Java development, the HTML structure to understand the people should be relatively easy to get started.Talk less, start now. Whether it is learning or practical, the first
before.Webdriverwait (DR, 10)Scans 1 page changes every 500 milliseconds in 10 seconds, ending when the specified element appears. Dr does not explain that the handle of the front operation Webdriver.firefox ()Is_displayed ()Whether the element is visible to the userClass Actionchains (Driver)Driver: Performing a user action instance webdriverGenerates the user's behavior. All actions are stored in the actionchains object. behavior that is stored through the perform (). Move_to_element (menu)Mo
));Wait.until (New expectedconditionPublic Boolean apply (Webdriver D) {Boolean loadcomplete = D.switchto (). FRAME ("Right_frame"). Findelement (By.xpath ("//center/div[@class = ' Welco ']/img") ). isdisplayed ();return loadcomplete;}});You can also estimate your time by Thread.Sleep (5000);//wait 5 seconds This is forcing the thread to rest6.firefox Security Strong, not allow cross-domain calls errorError Description: uncaught exception: [Exception
= driver.findelement (By.id ("Father")). Findelement (Bylinktext ("xxx"));4. NosuchelementfoundexceptionThe Findelement () and findelements () methods throw the exception when the corresponding element is not found.Findelements:Selenium Webdriver's Findelements () method allows you to get a collection of specified rules for situations where you need to operate on a similar set of elements.Example: Verify the number of Baidu home navigation links and print out their hyperlink addressImplementati
value ' + ' can be alteredThread.Sleep (3000);}Scroll automatically to your webelement:Point Hoveritem =driver.findelement (By.xpath ("Value")). GetLocation ();((Javascriptexecutor) driver). Executescript ("return window.title;");Thread.Sleep (6000);((Javascriptexecutor) driver). Executescript ("Window.scrollby (0," + (Hoveritem.gety ()) + ");Adjust your Page view by making changes right over here (Hoveritem.gety ()-400)(OR)((Javascriptexecutor) driver). Executescript ("Arguments[0].scrollintov
When you use the Webdriver action, clicking on the link in the main window will pop up the child window. At this point there will be two windows, such as the main window is MainWindow, and the child window is Detailwindow.1, use Detailwindow = Mainwindow.switchto (). window (Detailwindowhandle); Toggles and navigates to the child window.2, then close the child window, call Detailwindow. Quit (),3.MainWindow. SwitchTo (). Window (mainwindowhandle); Swi
anything elsewebdriverwait wait = (new webdriverwait (driver,10));Wait.until (New expectedconditionPublic Boolean apply (Webdriver D) {Boolean loadcomplete = D.switchto (). FRAME ("Right_frame"). Findelement (By.xpath ("//center/div[@class = ' Welco ']/img") ). isdisplayed ();return loadcomplete;}});You can also estimate your time by Thread.Sleep (5000);//wait 5 seconds This is forcing the thread to rest6.firefox Security Strong, not allow cross-doma
In the Java language, the code is as follows: Public voidscreenshot (Webdriver driver) {File Screenshotfile= ((takesscreenshot) driver). Getscreenshotas (Outputtype.file);//CodeSimpleDateFormat DF =NewSimpleDateFormat ("Yyyymmdd_hhmmss");//Set Date format//cut to the specified pathTry{fileutils.movefile (screenshotfile,NewFile ("test-output/snapshot/" + Df.format (NewDate ()) + ". jpg"));}Catch(IOException e) {System.out.println ("Can ' t save screens
There are three time-related methods in the Webdriver class:1.pageLoadTimeout2.setScriptTimeout3.implicitlyWaitPageloadtimeoutFrom selenium import WebdriverDriver = Webdriver.firefox ()Driver.set_page_load_timeout (10)SetscripttimeoutSet the time-out of the asynchronous script, the use of the same as Pageloadtimeout no longer write, asynchronous script is the async attribute of the JS script, can be execute
Partial HTML extraction of webdriver in seleniumDon't tell me that the webdriver in selenium uses driver. page_source. I just don't want to submit all the HTML documents for Soup every time. For the following Forum with the left and right structure, each change in content is really a small part of the entire HTML page. If I want to crawl the comments of all MOOC
parameter format requirement) -String size =string.valueof (Links.size ()); + //String size = integer.tostring (Links.size ()); A //String size = links.size () + ""; at //Verify the number of links -Selenesetestnghelper.assertequals ("8", size); - - //Print href attribute - //get all the elements in the list through a for loop, and then call the GetAttribute () method to get the attributes of the element - for(inti=0; I){ inSystem.out.pr
Purpose of Study:
Mastering the advanced applications of WebdriverFormal steps:
#-*-coding:utf-8-*- fromSeleniumImportWebdriver fromSelenium.webdriverImportActionchains fromSelenium.webdriver.support.uiImportSelect fromSelenium.webdriver.common.keysImportKeys fromSelenium.common.exceptionsImportwebdriverexceptionImportUnitTestImportOSImport TimeImportTracebackclassWebdriverapi (unittest. TestCase):defsetUp (self):#each use case executes and executes before a single use case is run
Prior to doing UI Automation testing often used in Webdriver and webelement two classes before the total feel a little silly for these two classes is not clearYesterday looked down before the code in combination with their own understanding of the difference between the two classes and the relationship to tidy up (welcome to make a brick) hope that the same doubts about the two classes of classmates have helpFirst, Webdriver.Webdriver I understand it'
that the cookie complies with selenium Webdriver by Driver.manage (). GetCookies () and Driver.manage (). Addcookie (CK); Get cookie Load cookie First, get cookie saved in Browser.dataImportJava.io.BufferedWriter;ImportJava.io.File;ImportJava.io.FileWriter;ImportJava.util.concurrent.TimeUnit;Importorg.openqa.selenium.By;ImportOrg.openqa.selenium.WebDriver;Importorg.openqa.selenium.WebElement;ImportOrg.open
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.