[java] Input button disabled attribute not correct if modified with JavaScript

75 views
Skip to first unread message

Tero Pikala

unread,
Sep 23, 2010, 11:14:50 AM9/23/10
to Selenium Users
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

Jayakumar C

unread,
Sep 24, 2010, 12:12:26 AM9/24/10
to seleniu...@googlegroups.com
Im not sure about Se2,but for Se1.x RC the solution would be,

sel.is_editable(locator)      .. this is python call

i guess the the java equivalent would be
sel.isEditable(locator);
       
Determines whether the specified input element is editable, ie hasn't been disabled.
This method will fail if the specified element isn't an input element.

For IDE,
verifyEditable | locator



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.




--
Jayakumar

Tero Pikala

unread,
Sep 24, 2010, 6:08:08 AM9/24/10
to Selenium Users
Thanks Jayakumar for pointing me to right direction.

Because SE2 has a wrapper (not sure if that's right term) for Selenium
I could do this:

Selenium selenium = new WebDriverBackedSelenium(driver, "http://
localhost/");
System.out.println(selenium.isEditable("normal"));
System.out.println(selenium.isEditable("disabledInHTML"));
System.out.println(selenium.isEditable("disabledInJavaScript"));
System.out.println(selenium.isEditable("disabledInJQuery"));


Maybe that's not ideal solution but it works for me.

Thanks again!



Tero Pikala



On Sep 24, 5:12 am, Jayakumar C <jayakumaree...@gmail.com> wrote:
> Im not sure about Se2,but for Se1.x RC the solution would be,
>
> sel.is_editable(locator)      .. this is python call
>
> i guess the the java equivalent would be
> sel.isEditable(locator);
>
> Determines whether the specified input element is editable, ie hasn't been
> disabled.
> This method will fail if the specified element isn't an input element.
>
> For IDE,
> verifyEditable | locator
>
> > selenium-user...@googlegroups.com<selenium-users%2Bunsubscribe@go oglegroups.com>
> > .
Reply all
Reply to author
Forward
0 new messages