`

selenium

    博客分类:
  • Java
 
阅读更多
<input type="checkbox" value="true" id="cb_ID74"/>
<input type="checkbox" value="true" id="ckb_ID73"/>

//input
//input[position()=1]
//input[2]
//input[last()]
//input[contains(@id, ‘cb')]

==========================================
<div id="div1">
	<h1>H1</h1>
	<table id="t1">
	</table>
</div>
<div id="div2">
	<h1>H2</h1>
	<table id="t2">
		<tr>
			<td id="td1">11</td>
			<td id=“td2”>22</td>
		</tr>
	</table>
</div>

//div[h1[text()='H2']]
//div[h1[text()='H2‘]]/child::*
//div[h1[text()='H2']]/descendant::*
//div[h1[text()='H2']]/descendant::td[@id="td2"]
//div[*[text()='H2']]/descendant::td[@id="td2"]
//div[contains(@id, '2')]/descendant::tr[td]
//div[contains(@id, '1')]/following-sibling::*

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




<table id="t1">
	<tr>
	   <td>11</td>
	   <td>22</td>
	</tr>
</table>
<table id="t2">
	<tr>
	   <td>33</td>
	   <td>44</td>
	</tr>
</table>

driver.findElement(By.xpath(“//tr[1]/td[1]”)) 11
table2.findElement(By.xpath(“//tr[1]/td[1]”)) 11
table2.findElement(By.xpath(“.//tr[1]/td[1]”)) 33


driver.switchTo().frame("i");
driver.findElement(By.id("txt1")).sendKeys("iframeTest");


driver.switchTo().window("new");
driver.findElement(By.id("kw")).sendKeys("WindowTest");



for (String handle : driver.getWindowHandles()) {  
	driver.switchTo().window(handle); 
	if (driver.getTitle().trim().equalsIgnoreCase("????,????")) {
		break;
	}
}
driver.findElement(By.id("kw")).sendKeys("WindowTest");



driver.switchTo().frame("i");
driver.findElement(By.id("txt1")).sendKeys("iframeTest");


driver.switchTo().frame("navigation");
// Selects the first frame on the page
driver.switchTo().defaultContent();
System.out.println(driver.getPageSource());
driver.switchTo().frame("detail");
driver.switchTo().frame("header");  X

<head>
<script type="text/javascript">
function display_alert() {
	alert("I am an alert box!!")
}
</script>
</head>
<body>
	<button id=“btn” onclick="display_alert()">test alert</button>
</body>

driver.findElement(By.id("btn")).click();
Alert alert = driver.switchTo().alert();
alert.accept();

//Open or Save Dialog
Robot robot = new Robot(); 
//Alt + S to select save 
robot.keyPress(KeyEvent.VK_ALT); 
robot.keyPress(KeyEvent.VK_S); 
robot.keyRelease(KeyEvent.VK_ALT); 
robot.delay(3000);
//Then type several chars
robot.keyPress(KeyEvent.VK_T);
robot.keyPress(KeyEvent.VK_E);
robot.keyPress(KeyEvent.VK_S);
robot.keyPress(KeyEvent.VK_T);
//Then press enter 
robot.keyPress(KeyEvent.VK_ENTER); 
robot.keyRelease(KeyEvent.VK_ENTER); 



AutoIt x = new AutoIt();
x.winActivate("File Download");
x.winWaitActive("File Download");
x.controlClick("File Download", "", "[TEXT:&Save]");
x.winWaitActive("Save As");
x.controlFocus("Save As", "", "[CLASS:Edit]");
x.send(“C:\\testSaveDialog”);
x.controlClick("Save As", "", "[TEXT:&Save]");
if(x.waitWinExists("Download complete", 50))
{
    x.controlClick("Download complete", "", "[TEXT:Close]");
}



<select name="combobox">
  <option value="1">item1</option>
  <option value="2" selected>item2</option>
  <option value="3">item3</option>
</select>

WebElement ComboBox = driver.findElement(By.name("combobox"));
Select select = new Select(ComboBox);
select.selectByVisibleText("item1");

Custom Select:
WebElement divList = driver.findElement(By.xpath("//body/div[last() - 1]/child::div"));
List<WebElement> options = divList.findElements(By.tagName("div"));

<table id="t1">
	<tr>
	   <td>td1</td>
	   <td>td2</td>
	</tr>
</table>


/**
 * Get specific cell element from table
 * @param table
 * @param rowIndex - start from 0
 * @param columnIndex - start from 0
 * @return
 */
public static WebElement getCell(WebElement table, int rowIndex, int columnIndex) {
	String xpathStr = ".//tr[" + (rowIndex + 1) + "]/td[" + (columnIndex + 1) + "]";
	return table.findElement(By.xpath(xpathStr));
}


//Able to execute Javascript directly using JavascriptExecutor
public void JavascriptExecutorTest()
{
  driver.get("http://www.baidu.com/");     ((JavascriptExecutor)driver).executeScript("document.getElementById(\"kw\").value = \"JavascriptExecutortest\"");

}


//Using JavaScript implement the functions which Webdriver API doesn’t provide.

/**
 * Get the inner HTML of the element by id
 * @param driver
 * @param id
 * @return
 */
public static String getInnerHTML(WebDriver driver, String id)
{
  JavascriptExecutor js = (JavascriptExecutor) driver;
  return (String) js.executeScript("return document.getElementById(" + "\"" + id + "\"" + ").innerHTML");
}

//continue to this website(not recommended)
driver.navigate().to("javascript:document.getElementById('overridelink').click()"); 





Appendix:
Firefinder plugin for Firefox

Official Selenium Blog
http://seleniumhq.wordpress.com/
Google Code - Selenium
http://code.google.com/p/selenium/
Google Group - WebDriver
http://groups.google.com/group/webdriver
Google Group - Selenium Users
http://groups.google.com/group/selenium-users
LinkedIn – Selenium-WebDriver
http://www.linkedin.com/groups/Selenium-WebDriver-4067187
XML Path Language (XPath)
 http://www.w3.org/TR/xpath/
Document Object Model (DOM)
http://www.w3.org/DOM/DOMTR




分享到:
评论

相关推荐

    selenium-server-standalone-2.25.0.jar

    由于Selenium Server在启动浏览器时做了手脚,所以Selenium Server会接收到所有由它启动的浏览器发送的请求。 (6).Selenium Server接收到浏览器的发送的Http请求后,自己重组Http请求,获取对应的Web页面。 (7)....

    Selenium2 Java自动化测试实战

    闲,所以有幸接触到 QTP、Selenium 等自动化测试工具,由于当时水平有限,学习也只停留在录制与回放的水 平上。再次学习 Selenium 是时隔一年之后,笔者有幸跳槽到一家互联网公司继续做 web 软件测试,发现项目适 合...

    ruby selenium-client-1.2.18.gem

    1. Download the latest version of Selenium RC 2. Unzip the file save it C:\selenium-remote-control-1.0.3 3. command prompt&gt;java -version –&gt; Version should grater than 1.6.0_5 4. command prompt go to ...

    seleniumwebdriver(python)第三版.rar

    selenium 是一个用于Web应用程序测试的工具。Selenium测试直接运行在浏览器中,就像真正的用户在操作一样。支持的浏览器包括IE(7, 8, 9, 10, 11),Mozilla Firefox,Safari,Google Chrome,Opera等。selenium 是...

    Selenium

    Selenium

    selenium RC与selenium webdriver的区别

    selenium RC与selenium webdriver的区别

    Selenium.Testing.Tools.Cookbook.2nd.Edition.178439251

    Over 90 recipes to help you build and run automated tests for your web applications with Selenium WebDriver About This Book Learn to leverage the power of Selenium WebDriver with simple examples that...

    selenium的初级使用说明 - Selenium介绍

    Selenium是ThoughtWorks公司开发的一套基于WEB应用的测试工具,直接运行在浏览器中,模拟用户的操作,主要包括三个部分selenium-IDE,selenium-core,selenium-rc 。它可以被用于单元测试,回归测试,冒烟测试,集成...

    Selenium自动化测试:基于Python语言.azw3

    Selenium是一个主要用于Web应用程序自动化测试的工具集合,在行业内已经得到广泛的应用。本书介绍了如何用Python语言调用Selenium WebDriver接口进行自动化测试。主要内容为:基于Python 的 Selenium WebDriver 入门...

    Selenium_v2.5

    Selenium_v2.5 Selenium_v2.5 Selenium_v2.5 Selenium_v2.5Selenium_v2.5 Selenium_v2.5

    selenium RC入门实例

    昨天群里有朋友问我selenium入门例子,我今天抽了点时间写了一段简单的代码,此代码适合刚刚学习selenium的人员参考,此代码是selenium2 RC 调用chrome driver访问百度,输入Jack_test 搜索. 代码里面含资源包:selenium...

    Selenium_中文API_手册.zip

    Selenium 不同于一般的测试工具。一般的脚本测试工具录制脚本,实际上都是通过拦截 浏览器收发的http 请求来实现的。事实上并没有办法录制用户对html 页面的操作。 当然,对那些执行压力测试的工具来说,这类模拟...

    Python爬虫——selenium模拟京东网站登录(一)

    from selenium import webdriver 2.浏览器获取驱动 需要下载跟chrome浏览器相匹配的驱动driverchrome.exe,详情见:根据电脑浏览器的版本下载相应的驱动chromedriver.exe,环境变量的配置,详情见这里Window 下配置...

    Selenium WebDriver实战宝典(吴晓华)

    本书是一本从入门到精通模式的Selenium WebDriver实战经验分享书籍。全书共分为四个部分:第1部分基础篇主要讲解自动化测试相关的基础理论、WebDriver 环境安装、单元测试工具的使用方法以及 WebDrvier的入门使用...

    selenium自动化22

    selenium

    Selenium IDE 插件 免费下载

    Selenium IDE 插件

    selenium私房菜系列

    Selenium是ThroughtWorks公司一个强大的开源Web功能测试工具系列,本系列现在主要包括以下4款: 1.Selenium Core:支持DHTML的测试案例(效果类似数据驱动测试),它是Selenium IDE和Selenium RC的引擎。 2....

    python中selenium库的基本使用详解

    什么是selenium selenium 是一个用于Web应用程序测试的工具。Selenium测试直接运行在浏览器中,就像真正的用户在操作一样。支持的浏览器包括IE(7, 8, 9, 10, 11),Mozilla Firefox,Safari,Google Chrome,Opera...

    selenium安装文件(jdk+seleniumIDE RC+安装使用文档)

    简单的selenium开发流程是: 1. 打开firefox,打开seleniumIDE进行脚本录制和回放,调试的时候可能需要firebug插件查看页面中的对象; 2. 生成junit4的java代码后,导入eclipse的java工程中,启动seleniumRC,然后...

    Python3+Selenium+Chrome实现自动填写WPS表单

      本文通过python3、第三方python库Selenium和谷歌浏览器Chrome,完成WPS表单的自动填写。 开发环境配置   python3的安装:略,网上都有教程。   Selenium的安装:在命令行输入pip3 install selenium并回车...

Global site tag (gtag.js) - Google Analytics