Selenium Xpath for Salesforce Page checkbox - “checked” attribute is not present

Viewed 1070

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

1 Answers

@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

Related