selenium


<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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值