Hi all.
With WebElement.isSelected() i could loop through a document and find al the checkboxes that are checked.
I want to form an Xpath that could give me all these checked checkboxes, and use
findElements(By.xpath("what-i-want-to-have"))
But
Can anyone give me a hint?
Thanks
--
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 https://groups.google.com/groups/opt_out.
driver.FindElement(By.Id("DocumentViewerradioHits")).GetAttribute("checked")driver.FindElement(By.XPath(desiredElementXPath)).DisplayedThis is what I want:
List<WebElement> checkedCheckboxes =
findElements(By.xpath("//input[@type='checkbox' and @someattribute='somevalue']"))
So what is @someattribute='somevalue' ?
Thanks
My,
for (String DocumentViewerradioHit : DocumentViewerradioHits){
Boolean isFound = driver.FindElement(By.Id("DocumentViewerradioHit")).GetAttribute("checked");
if (isFound
!= null && isFound != Boolean(false)){
//This is one good checked checkbox, do something with it
}
}
--
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.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/totLXIGCT6kJ.
List<WebElement> allCheckedCheckboxes = findElements(By.cssSelector("input:checked[type='checkbox']")i don't see any possible way to do this with xpath without a loop since xpath is a unique identifier that returns the first element that matches the path given.
also it is impossible to do what you want without a loop regardless of the identifier used. even the fucntion you said u used
List<WebElement> allCheckedCheckboxes = findElements(By.cssSelector("input:checked[type='checkbox']")
sill uses a loop inside the function.
its like asking someone to tell you all the cars he has seen today without him counting them (which would be guessing and that's not feasible in programming).
Do you really have a page with 10,000 checkboxes???
>Do you really think a page must have 10,000 checkboxes for the discussion to be meaningful ?
If that is the basis of your argument, yes I do.
List<WebElement> allCheckedCheckboxes = findElements(By.cssSelector("input:checked[type='checkbox']")
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/nJCSbKkq74EJ.
@MySelenium,
I guess you are still NOT getting the point here.
Lets take a step back here.
The below suggestion from Alex is the first hint :List<WebElement> allCheckedCheckboxes = findElements(By.cssSelector("input:checked[type='checkbox']")
This basically gives you back all of the checkboxes which are checked.
So why wouldnt you finding the corresponding equivalent for the same in XPath, NOT work for you ?
List<WebElement> allCheckedCheckboxes = driver.findElements(By.xPath("//input[@type='checkbox' and @checked='true']"));
List<WebElement> allCheckedCheckboxes = driver.findElements(By.xPath("//input[@type='checkbox' and string-length(@checked) > 0"));
I haven't had the chance to validate this xpath, because XPather plug-in that I normally use, doesnt work with my upgraded FF version :(
But wouldn't this do the trick for you ?
Regardless of why someone wants to do this, it can be done in XPath. The correct form is: "//input[@type='checkbox' and @checked=’checked’]". The “checked” attribute is one of a handful of strange HTML attributes that have no value, and so the browsers treat their value as either “”if not set or their name if set. And yes, even with 10,000 checkboxes and only 10 checked, the result of WebDriver.findElements("//input[@type='checkbox' and @checked=’checked’]") will be a list of only 10 elements. How efficient that is will depend on many factors, including how efficient the XPath engine itself is. Until and unless you benchmark the various forms, you’re just talking about ideas, not results.
Ross
From: seleniu...@googlegroups.com [mailto:seleniu...@googlegroups.com] On Behalf Of Krishnan Mahadevan
Sent: Monday, November 19, 2012 9:35 AM
To: seleniu...@googlegroups.com
Subject: Re: [selenium-users] Re: Xpath attribute of a checked checkbox?
@MySelenium,
Krishna.
You did not read my post.
It does not work if the attribute checked does not exist in the Html source. This seems to be non mandatory.
Anyone here knows how WebElement.isSelected() is implemented?
Thanks
driver.FindElement(By.Id("DocumentViewerradioHits")).GetAttribute("checked") == null;
Regardless of why someone wants to do this, it can be done in XPath. The correct form is: "//input[@type='checkbox' and @checked=’checked’]". The “checked” attribute is one of a handful of strange HTML attributes that have no value, and so the browsers treat their value as either “”if not set or their name if set. And yes, even with 10,000 checkboxes and only 10 checked, the result of WebDriver.findElements("//input[@type='checkbox' and @checked=’checked’]") will be a list of only 10 elements.
How efficient that is will depend on many factors, including how efficient the XPath engine itself is. Until and unless you benchmark the various forms, you’re just talking about ideas, not results.
Ross
From: seleniu...@googlegroups.com [mailto:seleniu...@googlegroups.com] On Behalf Of Krishnan Mahadevan
Sent: Monday, November 19, 2012 9:35 AM
To: seleniu...@googlegroups.com
Subject: Re: [selenium-users] Re: Xpath attribute of a checked checkbox?
@MySelenium,
I guess you are still NOT getting the point here.
Lets take a step back here.
The below suggestion from Alex is the first hint :
List<WebElement>allCheckedCheckboxes=findElements(By.cssSelector("input:checked[type='checkbox']")
This basically gives you back all of the checkboxes which are checked.
So why wouldnt you finding the corresponding equivalent for the same in XPath, NOT work for you ?
List<WebElement> allCheckedCheckboxes = driver.findElements(By.xPath("//input[@type='checkbox' and @checked='true']"));
Wouldn't this give you the same 9999 checkboxes that you are looking for on your page ?
Thanks & Regards
Krishnan Mahadevan
"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
On Mon, Nov 19, 2012 at 8:00 PM, MySelenium <my.selen...@gmail.com> wrote:
On 11/19/2012 03:28 PM, Peter Gale wrote:
>Do you really think a page must have 10,000 checkboxes for the discussion to be meaningful ?
If that is the basis of your argument, yes I do.If that's your understanding, then no, my page only has 9999 checkboxes.
--
--
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 https://groups.google.com/groups/opt_out.
You are looking at the wrong code!WebDriver DOESNOT use Javascript to do this but instead uses a JSONWireProtocol. Have you taken a look at RemoteWebElement (which implements the WebElement interface) ?
If not I suggest that you please start looking from there. The method you are referring am guessing is from the Selenium 1 API.�
On Tuesday, November 20, 2012, MySelenium wrote:
On 11/19/2012 04:13 PM, Ross Patterson wrote:
Regardless of why someone wants to do this, it can be done in XPath.� The correct form is: "//input[@type='checkbox' and @checked=�checked�]". ��The �checked� attribute is one of a handful of strange HTML attributes that have no value, and so the browsers treat their value as either ��if not set or their name if set.� And yes, even with 10,000 checkboxes and only 10 checked, the result of WebDriver.findElements("//input[@type='checkbox' and @checked=�checked�]") will be a list of only 10 elements.
As I said, this
WebDriver.findElements("//input[@type='checkbox' and @checked=�checked�]")
will only work if there's such an attribute with such value in the HTML source. It is not always so.
How efficient that is will depend on many factors, including how efficient the XPath engine itself is.� Until and unless you benchmark the various forms, you�re just talking about ideas, not results.
See my post to answer Alex, the implementation at package org.openqa.selenium.internal.selenesedriver.IsElementSelected.java explains me that each time I ask about one checkbox, WebDriver has to ask the Xpath engine. So this is not efficient with 10,000 checkboxes.
You might want to ask if the XPath engine could be efficient enough handling my extra requirement (that is "input:checked[type='checkbox']" instead of "input[type='checkbox']".
Yes, I think this simple xpath is too easy for the XPath engine to perform.
Regards,
My,
�
Ross
�
From: seleniu...@googlegroups.com [mailto:seleniu...@googlegroups.com] On Behalf Of Krishnan Mahadevan
Sent: Monday, November 19, 2012 9:35 AM
To: seleniu...@googlegroups.com
Subject: Re: [selenium-users] Re: Xpath attribute of a checked checkbox?
�
@MySelenium,
�
I guess you are still NOT getting the point here.
�
Lets take a step back here.
�
The below suggestion from Alex is the first hint :
List<WebElement>�allCheckedCheckboxes�=�findElements(By.cssSelector("input:checked[type='checkbox']")�
This basically gives you back all of the checkboxes which are checked.
�
So why wouldnt you finding the corresponding equivalent for the same in XPath, NOT work for you ?
�
List<WebElement> allCheckedCheckboxes = driver.findElements(B
--
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 https://groups.google.com/groups/opt_out.
�
�
--
Thanks & Regards
Krishnan Mahadevan
"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
--
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 https://groups.google.com/groups/opt_out.
�
�
Actually RemoteWebElement would call the JSonWireProtocol's command for IS_ELEMENT_SELECTED, which would eventually call the HtmlOption/HtmlInput.isSelected() function
On 11/20/2012 02:25 AM, Krishnan Mahadevan wrote:
You are looking at the wrong code!WebDriver DOESNOT use Javascript to do this but instead uses a JSONWireProtocol. Have you taken a look at RemoteWebElement (which implements the WebElement interface) ?
/**
* Returns <tt>true</tt> if this option is currently selected.
* @return <tt>true</tt> if this option is currently selected
*/
public boolean isSelected() {
return hasAttribute("selected") || selected_;
}
So, my assumption is true about performance punishment if we don't form a good Xpath/Css selector at the beginning
List<WebElement> elements = findElements(By.cssSelector("//input[type='checkbox']")) // Should better be "//input:checked[type='checkbox']"
// The following is not needed if we have a good Xpath/Css Selector
for (WebElement element : elements){
if (true == element.isSelected()){ // Does a JsonWireProtocol call from a Java runtime to the server (the Browser actually)
// do my job about checked checkboxes here
}
}
If not I suggest that you please start looking from there. The method you are referring am guessing is from the Selenium 1 API.
On Tuesday, November 20, 2012, MySelenium wrote:
On 11/19/2012 04:13 PM, Ross Patterson wrote:
Regardless of why someone wants to do this, it can be done in XPath. The correct form is: "//input[@type='checkbox' and @checked=’checked’]". The “checked” attribute is one of a handful of strange HTML attributes that have no value, and so the browsers treat their value as either “”if not set or their name if set. And yes, even with 10,000 checkboxes and only 10 checked, the result of WebDriver.findElements("//input[@type='checkbox' and @checked=’checked’]") will be a list of only 10 elements.
As I said, this
WebDriver.findElements("//input[@type='checkbox' and @checked=’checked’]")
will only work if there's such an attribute with such value in the HTML source. It is not always so.
How efficient that is will depend on many factors, including how efficient the XPath engine itself is. Until and unless you benchmark the various forms, you’re just talking about ideas, not results.
See my post to answer Alex, the implementation at package org.openqa.selenium.internal.selenesedriver.IsElementSelected.java explains me that each time I ask about one checkbox, WebDriver has to ask the Xpath engine. So this is not efficient with 10,000 checkboxes.
You might want to ask if the XPath engine could be efficient enough handling my extra requirement (that is "input:checked[type='checkbox']" instead of "input[type='checkbox']".
Yes, I think this simple xpath is too easy for the XPath engine to perform.
Regards,
My,
Ross
From: seleniu...@googlegroups.com [mailto:seleniu...@googlegroups.com] On Behalf Of Krishnan Mahadevan
Sent: Monday, November 19, 2012 9:35 AM
To: seleniu...@googlegroups.com
Subject: Re: [selenium-users] Re: Xpath attribute of a checked checkbox?
@MySelenium,
I guess you are still NOT getting the point here.
Lets take a step back here.
The below suggestion from Alex is the first hint :
List<WebElement>allCheckedCheckboxes=findElements(By.cssSelector("input:checked[type='checkbox']")
This basically gives you back all of the checkboxes which are checked.
So why wouldnt you finding the corresponding equivalent for the same in XPath, NOT work for you ?
List<WebElement> allCheckedCheckboxes = driver.findElements(B
--
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 https://groups.google.com/groups/opt_out.
--
Thanks & Regards
Krishnan Mahadevan
"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
--
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 https://groups.google.com/groups/opt_out.