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– Ishita Shah2018年05月02日 06:29:15 +00:00Commented May 2, 2018 at 6:29
-
With what language you write the tests? Pls, provide more information. Thanks.Zhivko.Kostadinov– Zhivko.Kostadinov2018年05月02日 07:50:32 +00:00Commented May 2, 2018 at 7:50
2 Answers 2
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 visibleRenold Reno– Renold Reno2018年05月03日 05:56:21 +00:00Commented May 3, 2018 at 5:56
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 visibleRenold Reno– Renold Reno2018年05月03日 06:00:21 +00:00Commented 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.shanila– shanila2018年05月03日 06:38:38 +00:00Commented May 3, 2018 at 6:38
-
Please Sent me full CodeRenold Reno– Renold Reno2018年05月03日 06:59:43 +00:00Commented 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>Renold Reno– Renold Reno2018年05月03日 07:01:14 +00:00Commented 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.shanila– shanila2018年05月03日 08:37:57 +00:00Commented May 3, 2018 at 8:37
Explore related questions
See similar questions with these tags.