3

Issue: I am seeing difficulty to handle checkbox of Salesforce page. I am not seeing any difference between two state of Checkbox. Both state checked and non-checked are showing same classes, attributes and text. I am not sure how to handle the checkbox on Salesforce. Please see below screenshot. We do have Ids but they are dynamic so I can not use IDs in my test case.

Platform: JAVA, TestNG, Eclipse, Selenium

Only difference I see is when checkbox is selected then I can see below:
<span lightning-input_input="" class="slds-checkbox_faux" xpath="1">
: : after ==$0
</span>

when it's not checked the I can see below:

<span lightning-input_input="" class="slds-checkbox_faux" xpath="1">
</span>

What I tried so far which is not helping me on Salesforce page:

    String rr = driver.findElement(xpath).getAttribute("checked"); // not working

    isSelected(); // Not Working 

    document.getElementById('myInput').checked // Can not use this becasue of Dynamic ID 

Below links I have gone through and tried locally on Salesforce page:

Selenium checkbox attribute "checked"

Xpath to determine checkbox "checked" attribute in Selenium IDE

Checkbox without checked attribute

enter image description here

supputuri
  • 13,644
  • 2
  • 21
  • 39
Mike ASP
  • 2,013
  • 2
  • 17
  • 24
  • Thanks @E.Wiest , you meant "//span[@class='slds-checkbox_faux'][contains(.,'after')]" ? just checked not working this xpath. – Mike ASP Apr 02 '20 at 23:42
  • I meant `contains(//span[@class="slds-checkbox_faux"],"after")` (previous one was a mistake) ? XPath expession will return a boolean. Returns true = checked, returns false = unchecked. – E.Wiest Apr 03 '20 at 00:15
  • check for element with `span.slds-checkbox_faux::after` css after selecting. If the elements count return `0` then check box is not selected. Let me know how it goes. – supputuri Apr 03 '20 at 02:04
  • @supputuri thanks for your reply. No did not help me. I think the only solution left is to fire SOQL query to see the value ID is available or not. – Mike ASP Apr 03 '20 at 16:21

1 Answers1

0

@Mike ASP I had similar scenario on a salesforce platform. Try using the xpath as
//*[@name='Existing_Tenant__c'] It worked for me. If you see multiple elements use index to get the element you intend to check. For ex (//*[@name='Existing_Tenant__c'])[1]. Just make sure that the xpath is highlighting the type='checkbox' tag in the DOM.

The following image is my scenario

enter image description here

  • my question was not just to locate element on Salesforce. Rather differentiate checked or non-checked element and create a unique Xpath for them. DOM is not showing difference between these two state for the element I highlighted in the question. – Mike ASP May 08 '20 at 18:04
  • 1
    Not sure why you want an unique xpath. In my case I used **driver.findElement(By.xpath("(//*[@name='Private__c'])[1])").isSelected()** that returns me true (if selected) or false (if not selected) – Sumanth_Nyx May 14 '20 at 17:23