How to get list of ALL the checkboxes from a page using Selenium Webdriver?

2,583 views
Skip to first unread message

Priya P

unread,
Dec 4, 2014, 8:46:23 PM12/4/14
to seleniu...@googlegroups.com
How to get list of ALL the checkboxes from a page using Selenium Webdriver?

Xiang Dong

unread,
Dec 4, 2014, 9:20:50 PM12/4/14
to seleniu...@googlegroups.com
//input[@type='checkbox']

using above xpath to retrieve all checkboxes from web page.

--david


Date: Thu, 4 Dec 2014 17:46:23 -0800
From: priyasi...@gmail.com
To: seleniu...@googlegroups.com
Subject: [selenium-users] How to get list of ALL the checkboxes from a page using Selenium Webdriver?


How to get list of ALL the checkboxes from a page using Selenium Webdriver?

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/6a6a43bf-a56c-4b61-b410-695870f0bdb4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rajeev Prabhakaran Nair

unread,
Dec 5, 2014, 1:07:36 AM12/5/14
to seleniu...@googlegroups.com

List<WebElement>    checkBoxes = driver.findElements(By.xpath("//input[@type='checkbox']"));
for (WebElement checkBox: checkBoxes) {
    System.out.println(checkBox.getAttribute()); // to iterate over each checkbox element.
   

Regards / Rajeev

Priya P

unread,
Dec 5, 2014, 1:39:08 AM12/5/14
to seleniu...@googlegroups.com
Thanks Rajeev,
But my page doesn't have the html tag as input and the attribute name is not checkbox , instead its selectid
Is the above checkbox attribute value generic ?
Regards
Priya

Priya P

unread,
Dec 5, 2014, 1:41:12 AM12/5/14
to seleniu...@googlegroups.com
The attribute value I mean

CH!NN@ K

unread,
Dec 5, 2014, 2:08:28 AM12/5/14
to seleniu...@googlegroups.com

---
Thanks & Regards,
Purushotham Karimbedu,
Druapl Developer and QA Engineer,
Website for Selenium : http://techlearn.in


On Fri, Dec 5, 2014 at 12:11 PM, Priya P <priyasi...@gmail.com> wrote:
The attribute value I mean


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

Rajeev Prabhakaran Nair

unread,
Dec 5, 2014, 3:20:50 AM12/5/14
to seleniu...@googlegroups.com
hi,

Can you paste the DOM here?

R


On Friday, 5 December 2014 07:16:23 UTC+5:30, Priya P wrote:

P Priya

unread,
Dec 7, 2014, 11:45:31 PM12/7/14
to seleniu...@googlegroups.com
Thanks Karimbedu for the link...

My html code has dynamic id attribute values , Only attribute that is  constant is the name ...

I tried using the following code by name, it gives me the result 0 while I have 5 checkboxes

     public void GetAllCheckboxlist()throws Exception {
          
           List<WebElement> s=driver.findElements(By.name("selectedTagIds"));
              
           System.out.println(s.size());
           
            for (int i = 0; i < s.size(); i++) {

            System.out.println(s.get(i).getText());
                }
              }



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

Rajeev Prabhakaran Nair

unread,
Dec 8, 2014, 12:40:24 AM12/8/14
to seleniu...@googlegroups.com
Can you paste your page html here?

Regards / Rajeev


On Friday, 5 December 2014 07:16:23 UTC+5:30, Priya P wrote:

Priya P

unread,
Dec 8, 2014, 12:56:18 AM12/8/14
to seleniu...@googlegroups.com
checkbox1:
<input type="checkbox" value="100" checked="" name="selectedTagIds" id="selectedTagIds_100">

checkbox2:
<input type="checkbox" value="101" checked="" name="selectedTagIds" id="selectedTagIds_101">

Rajeev Prabhakaran Nair

unread,
Dec 8, 2014, 1:29:36 AM12/8/14
to seleniu...@googlegroups.com
Have you tried this?
List<WebElement>    checkBoxes = driver.findElements(By.xpath("
//input[@type='checkbox']"));
for (WebElement checkBox: checkBoxes) {
    System.out.println(checkBox.getAttribute()); // to iterate over each checkbox element.
    }

your html contains type : checkbox? and it's an input.


checkbox1:
<input type="checkbox" value="100" checked="" name="selectedTagIds" id="selectedTagIds_100">

checkbox2:
<input type="checkbox" value="101" checked="" name="selectedTagIds" id="selectedTagIds_101">

Regards / Rajeev



On Friday, 5 December 2014 07:16:23 UTC+5:30, Priya P wrote:
Message has been deleted

Priya P

unread,
Dec 8, 2014, 6:22:40 PM12/8/14
to seleniu...@googlegroups.com
your code gave me a hint,
I modified to the following and it gave me the list of all checkboxes

    List<WebElement> allElements = driver.findElements(By.xpath("
/html/body/div[4]/div[2]/form/ol/li"));

            for (WebElement element: allElements) {
                  System.out.println(element.getText());
            }
        }


Thank you
Reply all
Reply to author
Forward
0 new messages