1. iframe To deal with

The search element must be in the corresponding ifarme Search for , Otherwise, it can't be found

 // The incoming parameter is frame The serial number of , from 0 Start 
driver.switchTo().frame(Int index);
// The incoming parameter is frame Of ID perhaps Name attribute
driver.switchTo().frame(String nameOrId);
// The incoming parameter is frameElement
driver.switchTo().frame(WebElement frameElement);
// Switch back to parent

2.  Pop up window processing

 // When only one window pops up , You don't need to pass in any parameters , Switch directly to the next window 
// Get the handle to the current window
String currentWindow = driver.getWindowHandle();
// Get the handles to all the windows
Set<String> handles = driver.getWindowHandles();
Iterator<String> it = handles.iterator();
while (it.hasNext()) {
String handle = it.next();
if (currentWindow.equals(handle))
WebDriver window = driver.switchTo().window(handle);
log.info("title,url = " + window.getTitle() + "," + window.getCurrentUrl());
 // Switch to the specified window , Most traversal 10 Time , Cycling is for stability , Sometimes you can't find it in a single browser ( String windowTitle )
for (int a = 0; a < =9; a++) {
Set<String> windowHandles = driver.getWindowHandles();
for (String handler : windowHandles) {
String title = driver.getTitle();
if (windowTitle.equals(title)) {
a = 10;

3.   Processing dialog alert\confirm\prompt

driver.switchTo().alert() You can get alert\confirm\prompt The object of the dialog box , Then use the method to operate it . The main methods of dialog operation are :

  • getText() Get its text value
  • accept() It's equivalent to clicking on it " confirm "
  • dismiss() It's like clicking " Cancel " Or cross out the dialog box
  • sendKeys() The input values , This alert\confirm Out-of-service , Will report a mistake

4.  Rich text editor

 // Rich text edit box processing 
driver.switchTo().frame("nameOrId"); // Navigate to the... Where the rich text input box is located frame
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.body.innerHTML='ABCDEFG'"); // adopt js Assign in

Java+selenium And WebDriver Common special cases such as iframe/ Pop ups ( Four ) More articles about

  1. Java+selenium And WebDriver The common way to encapsulate ( 8、 ... and )

    summary :WEB UI Automated testing generally uses POP( Page oriented programming ), The automated testing framework is divided into three layers , Sometimes if there are too many pages , Poor management , You can program for controls , That is, treat the control as a page , After all, the controls are limited , So the amount of code that encapsulates the page is much less , ...

  2. Java+selenium And WebDriver Simple operation of the browser ( One )

    The main ways to operate browsers come from org.openqa.selenium.WebDriver This interface These methods are all in org.openqa.selenium.remote.RemoteWebDriver this ...

  3. Java+selenium And WebDriver Simulate mouse and keyboard operation ( 6、 ... and )

    org.openqa.selenium.interactions.Actions class , It mainly defines some mouse to simulate users mouse, keyboard keyboard operation . For these operations , Use perform() Method to execute ...

  4. Java+selenium And WebDriver Of cookie, Wait and other advanced operations ( 5、 ... and )

    1. operation cookie // Add one more name = "name",value="value" Of cookie Cookie cookie = new Coo ...

  5. Java+selenium And WebDriver Locate page elements ( Two )

    Selenium-Webdriver Provides a powerful way to locate elements , Three methods are supported :  How to locate a single object , Positioning method and hierarchical positioning of multiple objects 1. Locate individual elements // For the attributes of an element, include id In the case of , PUSH ...

  6. 【selenium】- webdriver common api

    This article is organized by Xiaobian according to the video of MOOC , Please indicate the source and the author of the reprint . 1. common API 2. Open the url 3. Operating the browser quit() Not completely shutting down the process , Still taking up resources . 4. Input box operation 5. Select box operation 6. Special window operation ...

  7. 【selenium】- webdriver Common element positioning ( On )

    This article is organized by Xiaobian according to the video of MOOC , Please indicate the source and the author of the reprint . 1. Positioning of elements 2.By.id open Firefox, Open Baidu home page , Right click to select “ Use Firebug” Check out the elements . Click the button in the red box , Put the mouse pointer ...

  8. Java+selenium And WebDriver Throw exception analysis of ( 7、 ... and )

    NoSuchElementException 1. Check that the element's locator is correct 2. If the positioner is correct , Increase sleep time 3. If you can't find it after waiting enough time , Change the positioning mode of the positioner NoSuchWindowExce ...

  9. Java+selenium And WebDriver Operation of page elements ( 3、 ... and )

    1. Input box (text field or textarea) WebElement we = driver.findElement(By.id("id")); // Clear the input box w ...

Random recommendation

  1. BZOJ 4205: Card pairing

    4205: Card pairing Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 173  Solved: 76[Submit][Status][Discuss] ...

  2. Domain users execute Kingdee K/3 Error reporting solution

    Since last week's test of Jiayu accidentally turned out the company's attendance system , I don't dare to test in physics machine any more . Install virtual machine and Kingdee K/3 After the system , I've been tossed about by this error message for several days , One is not familiar with the software , On the other hand, there are almost no relevant articles . One . problem ...

  3. Dropplets – minimalist Markdown Blog platform

    Dropplets It's a simple blog platform , Focus on providing exactly what you need in a blogging solution . When it comes to basic blog functions , What you really want to do is write and publish , And this is Dropplets The best .Dropplets It's a ...

  4. angularjs - 415 (Unsupported Media Type)

    angularJs+springMVC angular The form submits a user Solid time , newspaper  angularjs - 415 (Unsupported Media Type) error !! as a result of $http({ u ...

  5. MySQL And Oracle Primary key Query Performance test results

    The test results are summarized as follows : 1.  Read by primary key :SQL form :SELECT * FROM table WHERE id=?. 1.1.  The primary key is a number . If all ID None of them exist , Pure comparison SQL Analytical power .MySQL analysis SQL Of ...

  6. 【 turn 】gcc warning: braces around scalar initializer ( Scalar initialization parentheses )

    Original website :http://stackoverflow.com/questions/3462513/gcc-warning-braces-around-scalar-initializer I have ...

  7. ●Splay Some questions of

    ● Personal feeling : Code length : There are many functions : ( It's a routine ): ( Very strong Splay, Worthy of “ Interval King ”) ●NOI2005 Maintenance series A problem that can be learned as a template , It contains many operations ( function ): Interval insertion , Delete , to update , Flip , Ask for information ...

  8. MySQL Summary of methods to prevent inventory oversold

    The problem of order oversold is the most important problem related to inventory items , Here I summarize the common methods 1. Simple handling [update & select Merge ]( Optimism lock ) beginTranse( Open transaction )$num = 1; try{ ...

  9. How to be in code blocks Use in mkl library

    For installation caffe, So it's installed mkl, Now I want to codeblock Used in the project mkl. Set up mkl environment variable : mkl After installation, the default is /opt/intel/mkl in , among /opt/intel/mkl/ ...

  10. Tetrahedron based light probe interpolation( Tetrahedral based Light Probe interpolation )

    In the current game engine , Use Light Probe It is a popular method to calculate the influence of global ambient light on dynamic objects . In the preprocessing phase, the scene is generated Light Probe after , The traditional method is to find the nearest 8 Next to each other Probe then ...