Java + Selenium-- treatment Alert pop

Introduction switchTo on the issue of handling alert popups. Many times, we enter a site, an alert box will pop,

Some of us directly off, and some may have to cancel the OK button, and some investigations alert box, you can run the user to enter text,

For example, a predetermined site information, you can enter the email address, the site receives a push e-mail every day.

===========================================================================

accept () method is to click the OK button;

 

dismiss () is to click the Cancel button above alert box,

 

getText () is to get the text inside the alert, such as printing on it.

 

sendKeys method as mentioned at the beginning of the input message as a predetermined content, there are even two about the certificate, not control, not being used.

 

=========================================================================================

 

package rjcs;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Set;

import org.openqa.selenium.interactions.Actions;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.testng.annotations.Test;
import org.openqa.selenium.*;

import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import org.openqa.selenium.OutputType;

import com.thoughtworks.selenium.SeleneseTestNgHelper;

public class ckqhh 
{
    public static void main(String[] args)
    
    {
         System.setProperty ( "webdriver.firefox.bin", "C: \\ Program Files (the x86) \\ \\ firefox.exe the Mozilla Firefox");     // set the installation path Firefox, preventing system can not find 
            
         FirefoxDriver Driver = new new FirefoxDriver ();         // initialize FireFox browser instance, and open the browser
         
        try
        {
             . driver.manage () window () Maximize ();.          // maximized window 
             
             the Thread.sleep ( 3000 );        
             
             . driver.manage () window () Maximize ();.          // maximized window 
             
             the Thread.sleep ( 3000 );



             driver.get("http://news.cyol.com/node_60799.htm");  
            
             Thread.sleep(8000);
             

             System.out.println (driver.switchTo () alert () getText ()..);   // handle alert box, get internal text messages 
             
             driver.switchTo () alert () the Accept ();..           // Click OK push button

             
             Thread.sleep(5000);
             
        }catch (Exception e) 
        {
            e.printStackTrace ();
        }finally 
        {
            driver.quit();
        
         }
   }
    

}

 

 

Results of the:

 

Recommended Action Network industry adolescent mental voting session is designed to enhance the influence and attention adolescent psychology profession in the social sphere, but also to take this opportunity to build a network platform for the exchange exhibition industry colleagues, and promote communication and interaction.

But because of this recommended action is the first time ever in the industry covering the entire industry events provinces and cities nationwide, still inadequate. In order to ensure fair and impartial activities, and resolutely put an end to the behavior of brush votes brush ticket agency for the purpose of profit,

Once discovered immediately cancel PARTICIPATING qualifications. Now learned that there are individual institutions in the name of helping the organizers of brush votes, hope all units to avoid being taken.

Guess you like

Origin www.cnblogs.com/xiaobaibailongma/p/12216282.html