1

I am not able to click the checkbox, I tried some XPath and CSS and id but I am not able to click on the checkbox

HTML Code:

<div class="row">
<table id="orderNoDropdown" class="table table-hover dataTable" aria-describedby="orderNoDropdown_info">
<thead>
<tr role="row">
<th class="checkBoxTh sorting_disabled" role="columnheader" rowspan="1" colspan="1">
<div class="checkbox checkbox-primary" style="float: right;">
<input id="thCheckBox" class="checkBox" type="checkbox"/>
<label for="thCheckBox" style="margin-bottom: 19px;"/>
</div>
</th>

XPath:

.//*[@id='orderNoDropdown']/thead/tr/th[1]/div/label

//th/div/label

CSS:

 div.checkbox.checkbox-primary > label
  • Add HTML snippet and the error which you are getting. – Ishita Shah May 2 '18 at 6:29
  • With what language you write the tests? Pls, provide more information. Thanks. – Zhivko.Kostadinov May 2 '18 at 7:50
1

In your examples the problem is that you are searching for the label being the direct descendant of the div by using >

Instead of this you should use ' ' which allos for any other elements at the same level - in this case an input

Generally you don't want to reference layout if possible so I would suggest the following:

XPATH

//input[@id="thCheckBox"]

CSS:

input#thCheckBox

As you have not indicated if other forms and form elements exist. If they do then you would need to add additional identifier to specify this form or this row for data entry, etc.

  • Thank you for ur answer. But i try this xpath and css same error occurred log4j:WARN appenders could be found for logger (freemarker.cache). log4j:WARN Please initialize the log4j system properly. log4j:WARN See logging.apache.org/log4j/1.2/faq.html#noconfig for more info. [Utils] Attempting to create C:\Users\Tabbie\tekafforde1\Tekafforde.com\test-output\Default suite\Default test.xml [Utils] Directory C:\Users\Tabbie\tekafforde1\Tekafforde.com\test-output\Default suite exists: true FAILED: Purchase_multi org.openqa.selenium.ElementNotVisibleException: element not visible – Renold Reno May 3 '18 at 5:56
0

Try using the following XPath,

//input[@id='thCheckBox']
  • Thank you for ur answer. But i try this xpath and css same error occurred log4j:WARN appenders could be found for logger (freemarker.cache). log4j:WARN Please initialize the log4j system properly. log4j:WARN See logging.apache.org/log4j/1.2/faq.html#noconfig for more info. [Utils] Attempting to create C:\Users\Tabbie\tekafforde1\Tekafforde.com\test-output\Default suite\Default test.xml [Utils] Directory C:\Users\Tabbie\tekafforde1\Tekafforde.com\test-output\Default suite exists: true FAILED: Purchase_multi org.openqa.selenium.ElementNotVisibleException: element not visible – Renold Reno May 3 '18 at 6:00
  • Add an "Explicit wait" to wait for an element to be visible and then use the above xpath to perform the click action. – shanila May 3 '18 at 6:38
  • Please Sent me full Code – Renold Reno May 3 '18 at 6:59
  • <div id="autofill" class="col-md-2 pull-right" style="margin-right: -46px;"> <label class="col-md-9 control-label read-label">Fill New Qty</label> <div class="col-md-1 checkbox checkbox-primary" style="margin-top: -7px;"> <input id="selectCheckBox" type="checkbox"/> <label for="selectCheckBox"/> </div> – Renold Reno May 3 '18 at 7:01
  • WebDriver wait = new WebDriverWait(driver,20); Element=wait.until(ExpectedConditions.VisibilityofElementlocated(By.Xpath("//input[@id='selectCheckBox']")); Add the above code for Explicit wait then perform the click operation. – shanila May 3 '18 at 8:37

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.