0

I'm out of ideas of how to click on radiobutton within an Salesforce application (no idea if that's the problem).

<flowruntime-radio-button-input-lwc data-data-rendering-service-uid="536" data-aura-rendered-by="2054:0" flowruntime-radiobuttoninputlwc_radiobuttoninputlwc-host="">
    <fieldset flowruntime-radiobuttoninputlwc_radiobuttoninputlwc="">
        <legend flowruntime-radiobuttoninputlwc_radiobuttoninputlwc="" class="slds-form-element__legend slds-form-element__label" aria-describedby="">
            <abbr flowruntime-radiobuttoninputlwc_radiobuttoninputlwc="" class="slds-required" title="required">*</abbr>
            <lightning-formatted-rich-text flowruntime-radiobuttoninputlwc_radiobuttoninputlwc="" class="slds-rich-text-editor__output">
                <span>Record Types
                </span>
            </lightning-formatted-rich-text>
        </legend>
        <div flowruntime-radiobuttoninputlwc_radiobuttoninputlwc="" class="slds-form-element__control">
            <span flowruntime-radiobuttoninputlwc_radiobuttoninputlwc="" class="slds-radio">
                <input flowruntime-radiobuttoninputlwc_radiobuttoninputlwc="" type="radio" name="RecordTypes" required="" id="RADIO-0-90" aria-labelledby="RADIO-LABEL-0-90" aria-describedby="" value="recordTypeChoices.0120E000001iGuHQAU">
                <label flowruntime-radiobuttoninputlwc_radiobuttoninputlwc="" class="slds-radio__label flow-radio-button-label" id="RADIO-LABEL-0-90" for="RADIO-0-90">
                    <span flowruntime-radiobuttoninputlwc_radiobuttoninputlwc="" class="slds-radio_faux">
                    </span>
                    <span flowruntime-radiobuttoninputlwc_radiobuttoninputlwc="" class="slds-form-element__label">
                        <lightning-formatted-rich-text flowruntime-radiobuttoninputlwc_radiobuttoninputlwc="" class="slds-rich-text-editor__output">
                            <span>Complaint
                            </span>
                        </lightning-formatted-rich-text>
                    </span>
                </label>
            </span>
            <span flowruntime-radiobuttoninputlwc_radiobuttoninputlwc="" class="slds-radio">
                <input flowruntime-radiobuttoninputlwc_radiobuttoninputlwc="" type="radio" name="RecordTypes" required="" id="RADIO-1-90" aria-labelledby="RADIO-LABEL-1-90" aria-describedby="" value="recordTypeChoices.0120E000001iGuJQAU">
                <label flowruntime-radiobuttoninputlwc_radiobuttoninputlwc="" class="slds-radio__label flow-radio-button-label" id="RADIO-LABEL-1-90" for="RADIO-1-90">
                    <span flowruntime-radiobuttoninputlwc_radiobuttoninputlwc="" class="slds-radio_faux">
                    </span>
                    <span flowruntime-radiobuttoninputlwc_radiobuttoninputlwc="" class="slds-form-element__label">
                        <lightning-formatted-rich-text flowruntime-radiobuttoninputlwc_radiobuttoninputlwc="" class="slds-rich-text-editor__output">
                            <span>Standard
                            </span>
                        </lightning-formatted-rich-text>
                    </span>
                </label>
            </span>
        </div>
    </fieldset>
</flowruntime-radio-button-input-lwc>

I can get the object: driver.findElement(By.cssSelector(".oneWorkspaceTabWrapper .slds-modal__container .slds-card__body flowruntime-radio-button-input-lwc"))

which is a top of the code snippet.

but if I try to go even one level deeper, for example by: driver.findElement(By.cssSelector(".oneWorkspaceTabWrapper .slds-modal__container .slds-card__body flowruntime-radio-button-input-lwc > fieldset"))

I get org.openqa.selenium.NoSuchElementException even though I can find this object with devtools.

My goal is to get to the span .slds-radio_faux - that's the radio button that I want to click.

I tried waits and switching to (because I thought it could be some sort of iframe), without any success. Any ideas? I had no experience with Salesforce-build apps before.

Thank you in advance!

Martin
  • 1
  • 1
  • 2
  • I've found a good way to copy HTML from the dev console. Simply right-click the `html` element at the top of the page, choose "edit as HTML", and copy-paste the relevant HTML as you desire. – C. Peck Aug 31 '22 at 17:29
  • This is just an educated guess as I cannot see the page. But looks like this modal window is loaded when something else is clicked, this is why you receive the NoSuchElementException. You would need to click everything before using selenium until the checkbox is visible on the page. – James Wagstaff Aug 31 '22 at 17:30
  • In addition to @JamesWagstaff observation, perhaps the modal resides inside an `iframe`, which you'd need to switch into before identifying elements in the modal. – C. Peck Aug 31 '22 at 17:33

2 Answers2

0

Presumably, there are two Complaint and Standard as:

<input flowruntime-radiobuttoninputlwc_radiobuttoninputlwc="" type="radio" name="RecordTypes" required="" id="RADIO-0-90" aria-labelledby="RADIO-LABEL-0-90" aria-describedby="" value="recordTypeChoices.0120E000001iGuHQAU">

and

<input flowruntime-radiobuttoninputlwc_radiobuttoninputlwc="" type="radio" name="RecordTypes" required="" id="RADIO-1-90" aria-labelledby="RADIO-LABEL-1-90" aria-describedby="" value="recordTypeChoices.0120E000001iGuJQAU">

Solution

As the element is a dynamic element so to click on the element with text as Complaint you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following locator strategies:

  • Using cssSelector:

    new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input#RADIO-0-90[aria-labelledby='RADIO-LABEL-0-90']"))).click();
    
  • Using xpath:

    new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='RADIO-0-90'][@aria-labelledby='RADIO-LABEL-0-90']"))).click();
    

Reference

You can find a detailed discussion on NoSuchElementException in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Unfortunately it's not working. I also tried to click on the elements that are before the fieldset first. The content of fieldset is loaded dynamically. Using Selenium I can click on the button that is below this fieldset and then the content of fieldset is being changed. I can click the radio button from the browser's console, so I tried: ((JavascriptExecutor) driver).executeScript("document.querySelector('SELECTOR').click();"); It gave me an error: org.openqa.selenium.JavascriptException: javascript error: Cannot read properties of null (reading 'click') – Martin Sep 01 '22 at 07:56
  • Your comment doesn't helps me either. Sorry, the answer didn't help you to solve your problem but how am I going to improve my post with the feedback _"Unfortunately it's not working"_? – undetected Selenium Sep 01 '22 at 18:11
0

Talking about the salesforce part, i think you need to move to frame first

driver = Edge(EdgeChromiumDriverManager().install(), options=options)  
driver.get(url)
driver.switch_to.frame(0)

And after move in this level frame you can move inside the webpage :).