0

HTML code

<div class="modal-footer slds-modal__footer" data-aura-rendered-by="2805:0">
<div class="rssDialogText grantAccessCheckbox packagingSetupUIRssDialogFooter" data-aura-rendered-by="2595:0" data-aura-class="packagingSetupUIRssDialogFooter">
<input type="checkbox" id="2596:0" data-aura-rendered-by="2600:0" class="uiInput uiInputCheckbox uiInput--default uiInput--checkbox" data-aura-class="uiInput uiInputCheckbox uiInput--default uiInput--checkbox" data-interactive-lib-uid="157">

Action:

Click the Checkbox

my xpath

//input[@data-aura-class='uiInput uiInputCheckbox uiInput--default uiInput--checkbox']

or

//input[@class='uiInput uiInputCheckbox uiInput--default uiInput--checkbox']

but both xpath not working, i am getting no such element

no such element: Unable to locate element: {"method":"xpath","selector":"//input[@class='uiInput uiInputCheckbox uiInput--default uiInput--checkbox']"}

checkbox click code:

driver.findElement(By.xpath("//input[@class='uiInput uiInputCheckbox uiInput--default uiInput--checkbox']")).click();
driver.findElement(By.xpath("//input[@data-aura-class='uiInp‌​ut uiInputCheckbox uiInput--default uiInput--checkbox']")).click();

Note: checkbox id dynamic

Please resolve or correct my xpath

enter image description here

Prabu
  • 3,550
  • 9
  • 44
  • 85
  • How about `//div[@data-aura-class="packagingSetupUIRssDialogFooter"]/input[@type="checkbox"]`? Also share code you use to click on checkbox – Andersson Mar 09 '17 at 09:07
  • how about `//div[contains(class,'uiInputCheckbox') and @type="checkbox"]` please change the class if you don't get unique element. Also are how are you verifying your xpath, hope you are using firebug for that. – Gaurang Shah Mar 09 '17 at 09:10
  • @andersson: chcekbox click code driver.findElement(By.xpath("//input[@class='uiInput uiInputCheckbox uiInput--default uiInput--checkbox']")).click(); driver.findElement(By.xpath("//input[@data-aura-class='uiInput uiInputCheckbox uiInput--default uiInput--checkbox']")).click(); – Prabu Mar 09 '17 at 09:11
  • your XPath seems to be correct (though can be optimized), please check whether the checkbox element is inside an `iframe`. Refer my complete answer here http://stackoverflow.com/a/40759300/2575259 about switching b/w frames – Naveen Kumar R B Mar 09 '17 at 09:13
  • @andersson: you xpath - SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//div[@data-aura-class="packagingSetupUIRssDialogFooter"]/in‌​put[@type="checkbox"‌​]' is not a valid XPath – Prabu Mar 09 '17 at 09:14
  • @naveen: not iframe this is located inside the model popup – Prabu Mar 09 '17 at 09:16
  • @Prabu, this might be because of some hidden characters- they might appears when you make copy/paste from StackOverflow. To check it- paste code in `cmd`/`Terminal`- hidden chars should appears as `??` – Andersson Mar 09 '17 at 09:19

1 Answers1

0

This might be timing issue: in case input field generated dynamically -it might be initially not present in DOM. Try below code to wait until checkbox present in DOM and it's clickable:

WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@data-aura-class='packagingSetupUIRssDialogFooter']/in‌put[@type='checkbox']"))).click();
Andersson
  • 51,635
  • 17
  • 77
  • 129