Selenium无法单击Salesforce应用程序中的单选按钮

e7arh2l6  于 2022-12-04  发布在  其他
关注(0)|答案(2)|浏览(134)

我不知道如何在Salesforce应用程序中单击单选按钮(不知道这是否是问题所在)。

<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>

我可以得到对象:driver.findElement(By.cssSelector(".oneWorkspaceTabWrapper .slds-modal__container .slds-card__body flowruntime-radio-button-input-lwc"))
这是代码片段的顶部。
但如果我试着更深入一层,比如说:driver.findElement(By.cssSelector(".oneWorkspaceTabWrapper .slds-modal__container .slds-card__body flowruntime-radio-button-input-lwc > fieldset"))
我得到了org.openqa.selenium.NoSuchElementException,尽管我可以用devtools找到这个对象。
我的目标是到达span .slds-radio_faux-这是我想要单击的单选按钮。
我试过等待和切换到(因为我认为它可能是某种iframe),没有任何成功。有什么想法吗?我以前没有使用Salesforce构建应用程序的经验。
提前感谢您!

avwztpqn

avwztpqn1#

据推测,有两种radio-button投诉***和***标准,如:

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

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

溶液

由于该元素是一个动态元素,因此要单击文本为***Complaint***的元素,您需要为elementToBeClickable()引入WebDriverWait,您可以使用以下locator strategies之一:

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

参考

有关NoSuchElementException的详细讨论,请参见:

  • NoSuchElementException,Selenium无法定位元素
slhcrj9b

slhcrj9b2#

谈到销售人员部分,我认为您需要首先转移到框架。

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

在这个水平框架中移动后,您可以在网页中移动:)。

相关问题