2

enter image description hereenter image description hereI want to know how to select single checkbox from multiple checkboxes one by one

Sceanrio:-

On a web Page, there are multiple entries having checkboxes in front of each entry. For each entry there is an edit button on right side. I want to select a single checkbox and then click on the edit button for that particular entry. on editing, a pop-up window will open. make some changes and click on the save button on the pop-up window. I need to do the same for each entry

I have added the html

  • if you need more detailed help, please provide HTML code – Yu Zhang Jul 23 '16 at 20:59
  • After the edit pop-up is submitted the checkbox remains checked? The html provided does not contains enough details, i expected an html that contains the structure of the table, for example the header + first 2-3 lines in full format(with edit part). The checkbox changes any attribute when is checked? The edit button appears only for selected checkbox? else i don't see the role of the checkbox to be checked, maybe it enables the edit button. We need details. – lauda Jul 25 '16 at 13:32
0

If you don't checkbox, try to get a selector for a checkbox from the body of the table, if multiple found the first one is used.

One way of clicking on the edit for the checkbox that is checked is to get an Xpath selector based on the checked value.

Please provide html code for what the image is describing for a more particular answer.

<input id="ctl00_cPH_rptrDisplayRecords_ctl03_chkMoveTranSingle" name="ctl00$cPH$rptrDisplayRecords$ctl03$chkMoveTranSingle" value="2469035" type="checkbox">

<input id="ctl00_cPH_rptrDisplayRecords_ctl05_chkMoveTranSingle" name="ctl00$cPH$rptrDisplayRecords$ctl05$chkMoveTranSingle" value="2469031" type="checkbox">

<input id="ctl00_cPH_rptrDisplayRecords_ctl08_chkMoveTranSingle" name="ctl00$cPH$rptrDisplayRecords$ctl08$chkMoveTranSingle" value="2781014" type="checkbox">

<input id="ctl00_cPH_rptrDisplayRecords_ctl02_chkMoveTranSingle" name="ctl00$cPH$rptrDisplayRecords$ctl02$chkMoveTranSingle" value="2469037" type="checkbox">
3

You have not provided HTML code, but please feel free to use the following example as a reference:

Say your HTML codes looks like:

<table class="transaction-table" 
    <ul
        <li value="152" /li>
        <li value="153" /li>
        <li value="154" /li>
    /ul>
/table>

where each element li represent each transaction row.

What you can do is:

from selenium import webdriver

firefox = webdriver.Firefox()
firefox.get("put your url here");
transactionElements = firefox.find_elements_by_css_selector("table[class='transaction-table'] li");
for element in transactionElements:
    element.click()

Hope it helps.

0

Try this in Java,

List<WebElement> elements=driver.findElements(By.xpath(".//*[starts-with(@id,'ct100_cPH_rptrDisplayRecords')]"));
int numberOfElements=elements.size();
for(int i=0;i<numberOfElements;i++){
    elements=driver.findElements(By.xpath(".//*[starts-with(@id,'ct100_cPH_rptrDisplayRecords')]"));
    elements.get(i).click();
    //click edit button and manage the popup
    .........
    .........
    // Uncomment below code if the selection of the check box is not automatically cleared on closing the popup
    /* elements=driver.findElements(By.xpath(".//*[starts-with(@id,'ct100_cPH_rptrDisplayRecords')]"));
    elements.get(i).click(); */
}
  • Hi, Same id is for Checkbox, Edit button and Image – saurabh kumar Jul 26 '16 at 8:06
  • Can you share HTML code for checkbox, edit button and image – stackoverflow Jul 26 '16 at 10:04
-1
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class test6 {

    public static void main(String[] args) {
        WebDriver driver=new FirefoxDriver();
        driver.navigate().to("url");
        List <WebElement> li= driver.findElements(By.xpath("//input[@type='checkbox']"));
        System.out.println(li.size());
                for(int i=0;i<=li.size()-1;i++)
                {
                    li.get(i).click();
                }

        }

 }
  • Your answer would be better if it described how this solution solved the OP's problem. – Kate Paulk Mar 16 '18 at 11:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.