Hi
I'm pretty new to Selenium 2 and one of the test I've tried to write
was to validate if input buttons are disabled/enabled properly. It
seems that if I change disabled attribute with JavaScript I'm getting
incorrect results back from getAttribute() method.
I've tried to add some delay after page has loaded to make sure all
events have time to execute but that doesn't seem to have any impact.
I have following test page to reproduce issue
<html>
<head>
<script type="text/javascript"
src="
http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/
jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('*[id=disabledInJQuery]').attr("disabled", true);
});
function onLoad() {
document.getElementById('disabledInJavaScript').disabled = true;
}
</script>
</head>
<body onload="onLoad();">
<form method="POST" action="/">
<input type="button" id="normal" value="Normal"/>
<input type="button" id="disabledInHTML" value="Disabled in HTML"
disabled="disabled" />
<input type="button" id="disabledInJavaScript" value="Disabled in
JavaScript" />
<input type="button" id="disabledInJQuery" value="Disabled in
JQuery" />
</form>
</body>
</html>
and my Selenium code is
package com.pikala.test;
import
org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.*;
public class ScribbleTest {
private WebDriver driver;
@BeforeTest
public void setupDriver() {
driver = new FirefoxDriver();
}
@AfterTest
public void quit() {
driver.quit();
}
@Test
public void testButtonStates() {
WebElement elm;
driver.get("
http://localhost/scribble.html");
delayFor(1000);
elm = driver.findElement(By.id("normal"));
System.out.println("normal button disabled: " +
elm.getAttribute("disabled"));
elm = driver.findElement(By.id("disabledInHTML"));
System.out.println("disabled button disabled: " +
elm.getAttribute("disabled"));
elm = driver.findElement(By.id("disabledInJavaScript"));
System.out.println("javascript button disabled: " +
elm.getAttribute("disabled"));
elm = driver.findElement(By.id("disabledInJQuery"));
System.out.println("jquery button disabled: " +
elm.getAttribute("disabled"));
}
private void delayFor(int ms) {
long end = System.currentTimeMillis() + ms;
while (System.currentTimeMillis() < end) {
// do nothing.
}
}
}
Any ideas and help would be appreciated! I really like this stuff but
just need get my head around these initial problems.
Thanks
Tero Pikala