在Salesforce中选择动态输入框-Selenium / Python

时间:2019-07-03 14:30:33

标签: python selenium-webdriver salesforce

如何使用Selenium为python选择以下输入框(id = 2258:0)? id和其他元素一样动态变化。

<label class="label inputLabel uiLabel-left form-element__label uiLabel" for="2258:0" data-aura-rendered-by="3789:0" data-aura-class="uiLabel"><span class="" data-aura-rendered-by="3790:0">Close Date</span><div class="tooltip-trigger uiTooltip" aria-describedby="tt-for-2283:0" tabindex="0" data-aura-rendered-by="2286:0" data-aura-class="uiTooltip" data-proxy-id="aura-pos-lib-4" id="2286:0"><lightning-icon class="tooltipIcon slds-button__icon slds-icon-utility-info slds-icon_container forceIcon" data-data-rendering-service-uid="963" data-aura-rendered-by="2282:0" data-aura-class="forceIcon"><lightning-primitive-icon lightning-primitiveicon_primitiveicon-host=""><svg lightning-primitiveIcon_primitiveIcon="" focusable="false" data-key="info" aria-hidden="true" class="slds-icon slds-icon_xx-small"><use lightning-primitiveIcon_primitiveIcon="" xlink:href="/_slds/icons/utility-sprite/svg/symbols.svg?cache=9.26.0#info"></use></svg></lightning-primitive-icon></lightning-icon><span class="tooltip-invisible" role="tooltip" id="tt-for-2283:0" data-aura-rendered-by="2288:0">Date the Opportunity Product isClosed</span></div><!--render facet: 3793:0--></label>
    <div class="tooltip-trigger uiTooltip" aria-describedby="tt-for-2283:0" tabindex="0" data-aura-rendered-by="2286:0" data-aura-class="uiTooltip" data-proxy-id="aura-pos-lib-4" id="2286:0"><lightning-icon class="tooltipIcon slds-button__icon slds-icon-utility-info slds-icon_container forceIcon" data-data-rendering-service-uid="963" data-aura-rendered-by="2282:0" data-aura-class="forceIcon"><lightning-primitive-icon lightning-primitiveicon_primitiveicon-host=""><svg lightning-primitiveIcon_primitiveIcon="" focusable="false" data-key="info" aria-hidden="true" class="slds-icon slds-icon_xx-small"><use lightning-primitiveIcon_primitiveIcon="" xlink:href="/_slds/icons/utility-sprite/svg/symbols.svg?cache=9.26.0#info"></use></svg></lightning-primitive-icon></lightning-icon><span class="tooltip-invisible" role="tooltip" id="tt-for-2283:0" data-aura-rendered-by="2288:0">Date the Opportunity Product isClosed</span></div>
        <lightning-icon class="tooltipIcon slds-button__icon slds-icon-utility-info slds-icon_container forceIcon" data-data-rendering-service-uid="963" data-aura-rendered-by="2282:0" data-aura-class="forceIcon"><lightning-primitive-icon lightning-primitiveicon_primitiveicon-host=""><svg lightning-primitiveIcon_primitiveIcon="" focusable="false" data-key="info" aria-hidden="true" class="slds-icon slds-icon_xx-small"><use lightning-primitiveIcon_primitiveIcon="" xlink:href="/_slds/icons/utility-sprite/svg/symbols.svg?cache=9.26.0#info"></use></svg></lightning-primitive-icon></lightning-icon>
        <span class="tooltip-invisible" role="tooltip" id="tt-for-2283:0" data-aura-rendered-by="2288:0">Date the Opportunity Product isClosed</span>
        <div class="tooltip-trigger uiTooltip" aria-describedby="tt-for-2283:0" tabindex="0" data-aura-rendered-by="2286:0" data-aura-class="uiTooltip" data-proxy-id="aura-pos-lib-4" id="2286:0"><lightning-icon class="tooltipIcon slds-button__icon slds-icon-utility-info slds-icon_container forceIcon" data-data-rendering-service-uid="963" data-aura-rendered-by="2282:0" data-aura-class="forceIcon"><lightning-primitive-icon lightning-primitiveicon_primitiveicon-host=""><svg lightning-primitiveIcon_primitiveIcon="" focusable="false" data-key="info" aria-hidden="true" class="slds-icon slds-icon_xx-small"><use lightning-primitiveIcon_primitiveIcon="" xlink:href="/_slds/icons/utility-sprite/svg/symbols.svg?cache=9.26.0#info"></use></svg></lightning-primitive-icon></lightning-icon><span class="tooltip-invisible" role="tooltip" id="tt-for-2283:0" data-aura-rendered-by="2288:0">Date the Opportunity Product isClosed</span></div>

<div class="form-element" data-aura-rendered-by="2262:0"><input class=" input" type="text" aria-describedby="" id="2258:0" data-aura-rendered-by="2263:0" data-interactive-lib-uid="16" data-proxy-id="aura-pos-lib-13"><a class="datePicker-openIcon display" aria-haspopup="true" data-aura-rendered-by="2265:0" href="javascript:void(0);"><span class="assistiveText" data-aura-rendered-by="2266:0">Date Picker</span></a><!--render facet: 2268:0--><!--render facet: 2269:0--></div>
    <input class=" input" type="text" aria-describedby="" id="2258:0" data-aura-rendered-by="2263:0" data-interactive-lib-uid="16" data-proxy-id="aura-pos-lib-13">
    <a class="datePicker-openIcon display" aria-haspopup="true" data-aura-rendered-by="2265:0" href="javascript:void(0);"><span class="assistiveText" data-aura-rendered-by="2266:0">Date Picker</span></a>

我尝试了以下代码,但没有成功:

driver.find_element_by_xpath("//*[contains(text(), 'Close Date')]/following-sibling::input")

3 个答案:

答案 0 :(得分:0)

使用这种格式的XPATH

//div[@id="container-3"]/fuse-content/div/div[2]/

代替

//*[contains(text(), 'Close Date')]/following-sibling::input

答案 1 :(得分:0)

使用下面的CSS定位器应该可以工作-

driver.find_element_by_css_selector("div.form-element > input")

答案 2 :(得分:0)

请检查该元素是否存在任何IFRME,然后尝试:

//*[contains(text(), 'Close Date')]/following-sibling::input