--
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.
web=driver.findElement(By.xpath("//input[@name='GPP']"));
web.click();
/**
* Returns whether the element is checked or selected.
*
* @param {!Element} element The element to check.
* @return {boolean} Whether the element is checked or selected.
*/
bot.dom.isSelected = function(element) {
if (!bot.dom.isSelectable(element)) {
throw new bot.Error(bot.ErrorCode.ELEMENT_NOT_SELECTABLE,
'Element is not selectable');
}
var propertyName = 'selected';
var type = element.type && element.type.toLowerCase();
if ('checkbox' == type || 'radio' == type) {
propertyName = 'checked';
}
return !!bot.dom.getProperty(element, propertyName);
};
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
If there is more than one element that matches a locator Selenium/WebDriver will always return the first instance of the element that it finds. In this case you would still get a true/false response from .isSelected().
From: seleniu...@googlegroups.com [mailto:seleniu...@googlegroups.com] On Behalf Of Rajat Jindal
Sent: 10 May 2012 11:20
To: seleniu...@googlegroups.com
Subject: [selenium-users] Re: Find out if a checkbox is selected
My 2 cents.
Can you confirm if the xpath //input[@name='GPP'] returns just one element. [More then one input element with name 'GPP' may be present in your webpage] or if it returns element at all. Please verify it using, may be, web.getAttribute('GPP').
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/AmtcICcbEC8J.
I would suggest not executing your own JavaScript instead of using the built in functions supplied by Selenium/WebDriver, they have been written, tried, and tested over a number of years and are going to be much more stable/accurate than anything you hand craft. If there is a problem with them raise a bug so it can be fixed and you don’t have to maintain your own JavaScript codebase.
If you insist on doing this there is little point in using selenium in the first place.
From: seleniu...@googlegroups.com [mailto:seleniu...@googlegroups.com] On Behalf Of Rajat Jindal
Sent: 10 May 2012 12:25
To: seleniu...@googlegroups.com
Subject: [selenium-users] Re: Find out if a checkbox is selected
If you are sure there will always be one element with name GPP, then try following:
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/oIVE39wYYMUJ.
Maxim, please feel free to prove me wrong with some reproducible steps
WebDriver driver = new InternetExplorerDriver();
WebDriverBackedSelenium rc = new WebDriverBackedSelenium(driver, "");
driver.get("http://www.thejekels.com/dojo/demo/checkboxtree/");
if (driver.getWindowHandles().size()==0){
throw new RuntimeException("Hello!");
}
String xpath = "//INPUT[@type='checkbox' and @id='cbt_CheckBox_1']";
new WebDriverWait(driver, 5000).until(ExpectedConditions.presenceOfElementLocated(By.xpath(xpath)));
WebElement checkbox = driver.findElement(By.xpath(xpath));
System.out.println("============Before click");
System.out.println("isSelected via webdriver: "+checkbox.isSelected());
System.out.println("isSelected via rc: "+rc.isChecked(xpath));
System.out.println("isSelected via value attribute: "+checkbox.getAttribute("value"));
checkbox.click();
System.out.println("============After click");
System.out.println("isSelected via webdriver: "+checkbox.isSelected());
System.out.println("isSelected via rc: "+rc.isChecked(xpath));
System.out.println("isSelected via value attribute: "+checkbox.getAttribute("value"));
============Before click
isSelected via webdriver: true
isSelected via rc: true
isSelected via value attribute: mixed
============After click
isSelected via webdriver: true
isSelected via rc: true
isSelected via value attribute: unchecked
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/DqcR-iqJiPsJ.
Had a quick look (and it needs more investigation) but I would say that you have a bug with the checkbox implementation there,
The checked attribute is not changed when you check/uncheck the checkbox (I manually tested this using firebug), instead it is modifying the value, and a custom attribute called aria-checked. I haven’t investigated the JavaScript that is being fired by the onCheck event but my guess is that modification of the checked attribute is being suppressed so that the value attribute and the custom attribute aria-checked is used instead.
In this case the checked attribute of the input element is always set so if you check to see if it is set or not it should always return true. Selenium/WebDriver is doing this correctly and reporting the state of the checked attribute correctly.
There is no bug with Selenium here, there is a bug with the implementation of the checkbox control and by working around it you are effectively coding your test to deal with invalid behaviour rather than getting a bug fixed.
I would also highlight that the only valid values for the attribute checked are:
“checked”
“”
It used to be just the presence of a checked attribute that was validated, but to make it XML compliant it had to be modified to have a value.
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/oXNFHr9cs2sJ.