WebDriver 中使用 Javascript
2012-11-26 13:19
411 查看
Use Javascript in WebDriver
package com.example.tests;
import java.io.File;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.Select;
public class BenbriaSele01 {
private WebDriver driver;
private String baseUrl;
private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {
//Use IE driver
File file = new File("E:/SW/Selenium/IEDriverServer32.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
capabilities.setCapability("ignoreProtectedModeSettings",true);
driver = new InternetExplorerDriver(capabilities);
// //Use Firefox
// driver = new FirefoxDriver();
baseUrl = "http://10.1.3.12/";
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testBenbriaSele01() throws Exception {
// driver.get(baseUrl + "/blazecast/login.jsf");
driver.get(baseUrl);
driver.findElement(By.id("username")).sendKeys("admin");
driver.findElement(By.id("password")).sendKeys("admin");
// driver.findElement(By.id("login_submit")).click();
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.getElementById(\"login_submit\").click()",true);
}
@After
public void tearDown() throws Exception {
// driver.quit();
// String verificationErrorString = verificationErrors.toString();
// if (!"".equals(verificationErrorString)) {
// fail(verificationErrorString);
// }
System.out.println("tearDown!");
}
}
package com.example.tests;
import java.io.File;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.Select;
public class BenbriaSele01 {
private WebDriver driver;
private String baseUrl;
private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {
//Use IE driver
File file = new File("E:/SW/Selenium/IEDriverServer32.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
capabilities.setCapability("ignoreProtectedModeSettings",true);
driver = new InternetExplorerDriver(capabilities);
// //Use Firefox
// driver = new FirefoxDriver();
baseUrl = "http://10.1.3.12/";
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testBenbriaSele01() throws Exception {
// driver.get(baseUrl + "/blazecast/login.jsf");
driver.get(baseUrl);
driver.findElement(By.id("username")).sendKeys("admin");
driver.findElement(By.id("password")).sendKeys("admin");
// driver.findElement(By.id("login_submit")).click();
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.getElementById(\"login_submit\").click()",true);
}
@After
public void tearDown() throws Exception {
// driver.quit();
// String verificationErrorString = verificationErrors.toString();
// if (!"".equals(verificationErrorString)) {
// fail(verificationErrorString);
// }
System.out.println("tearDown!");
}
}
相关文章推荐
- webdriver定位页面元素时使用set_page_load_time()和JavaScript停止页面加载
- 使用webdriver中的JavascriptExecutor执行js改变DOM属性
- 【selenium webdriver】selenium.JavascriptExecutor.executeScript() 使用实例
- 如何使用Selenium WebDriver报告Javascript错误
- 安卓使用webView中的JavaScript代码
- 第五章:操纵 DOM使用 JavaScript 即时更新 Web 页面
- webDriver 使用笔记(一)
- Selenium WebDriver的使用(二)
- selenium+python自动化测试(二)--使用webdriver操作浏览器
- WebDriver使用指南(完整篇)
- 【软件测试】Java中Selenium Webdriver的使用
- 【WebDriver】调用JavaScript
- WebView原生方法---使用javascript调用android代码
- 软件测试自动化之路(7)----在Web GUI Automation Test中使用JavaScript应注意的问题
- Python+WebDriver 启动Firefox时使用profile
- Cucumber java + Webdriver (5) Tags的使用
- Android WebView中的JavaScript代码使用
- Code9 点击按钮使用JavaScript清除Web控件的值
- Selenium WebDriver 使用IE
- 在Selenium Webdriver中使用XPath Contains、Sibling函数定位