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
Bharat Mane
6,78512 gold badges42 silver badges69 bronze badges
asked May 2, 2018 at 5:04
2
  • Add HTML snippet and the error which you are getting. Commented May 2, 2018 at 6:29
  • With what language you write the tests? Pls, provide more information. Thanks. Commented May 2, 2018 at 7:50

2 Answers 2

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.

answered May 2, 2018 at 12:09
1
  • 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 Commented May 3, 2018 at 5:56
0

Try using the following XPath,

//input[@id='thCheckBox']
Bharat Mane
6,78512 gold badges42 silver badges69 bronze badges
answered May 2, 2018 at 11:29
5
  • 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 Commented May 3, 2018 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. Commented May 3, 2018 at 6:38
  • Please Sent me full Code Commented May 3, 2018 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> Commented May 3, 2018 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. Commented May 3, 2018 at 8:37

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.