zoukankan      html  css  js  c++  java
  • Selenium启动Firefox示例(java版)

    本文示例使用selenium启动Firefox,并将浏览器窗口最大化,在百度搜索框内输入“HelloWorld”,最后点击搜索按钮。

    源代码如下:

     1 package com.selenium.test;
     2 
     3 import java.util.concurrent.TimeUnit;  
     4 import org.openqa.selenium.By;
     5 import org.openqa.selenium.WebDriver;
     6 import org.openqa.selenium.WebElement;
     7 import org.openqa.selenium.firefox.FirefoxDriver;  
     8 
     9 public class testGome {  
    10     public static void main(String[] args) {   
    11         //如果火狐浏览器没有默认安装在C盘,需要制定其路径  
    12         //System.setProperty("webdriver.firefox.bin", "D:/Program Files (x86)/Mozilla Firefox/firefox.exe");   
    13         System.setProperty("webdriver.firefox.marionette","C:\Program Files (x86)\Mozilla Firefox\geckodriver.exe");  
    14         //WebDriver driver=new FirefoxDriver();              C:Program Files (x86)Mozilla Firefox  
    15         //定义驱动对象为 FirefoxDriver 对象  
    16         WebDriver driver = new FirefoxDriver();  
    17         //驱动的网址  
    18         driver.get("https://www.baidu.com/");  
    19         //浏览器窗口变大  
    20         driver.manage().window().maximize();  
    21         //定位输入框元素  
    22         WebElement txtbox = driver.findElement(By.name("wd"));  
    23         //在输入框输入文本  
    24         txtbox.sendKeys("HelloWorld");  
    25         //定位按钮元素  
    26         WebElement btn = driver.findElement(By.id("su"));  
    27         //点击按钮  
    28         btn.click();  
    29         //关闭驱动  
    30         driver.close();     
    31     }   
    32 }

     下一篇文章介绍python版Selenium启动Firefox浏览器。

  • 相关阅读:
    js-格式化数字保留两位小数-带千分符
    java-byte[]图片在页面展示
    bootstrap-fileupload-上传文件控件
    css-让div永远在最底部
    hibernate-DetachedCriteria实现关联表条件复查
    eclipse-搭建maven的war项目集合spring注解方式
    spring-注解
    eclipse-mvn打包跳过junit测试类
    Spring-注解控件介绍
    java-读取类中的属性名称和值
  • 原文地址:https://www.cnblogs.com/muchengnanfeng/p/9507256.html
Copyright © 2011-2022 走看看