簡體   English   中英

Python selenium Z99938282F04071859941E18F16EFjsCF42Z 選項來自 ZD18B8624A0F5F721DA7B8236-select556ng

[英]Python selenium select option from angular js ng-select

我一直在嘗試從下拉列表中進行選擇,但似乎無法弄清楚如何。

這是我想要得到的:

<div _ngcontent-wdj-c58="" class="delivery-group">
    <span _ngcontent-wdj-c58="">Guaranteed Delivery Time:</span>
    <div _ngcontent-wdj-c58="" class="select-container">
        <ng-select _ngcontent-wdj-c58="" class="ng-select ng-select-single ng-select-clearable ng-pristine ng-invalid ng-select-bottom ng-touched" formcontrolname="guaranteedDeliveryTime" notfoundtext="No options" placeholder="Choose" role="listbox">
            <div class="ng-select-container">
                <div class="ng-value-container">
                    <div class="ng-placeholder">Choose</div>
                    <!---->
                    <!---->
                    <div class="ng-input"><input role="combobox" type="text" autocorrect="off" autocapitalize="off" autocomplete="a67359450338" readonly="" aria-expanded="false"></div>
                    </div>
                    <!---->
                    <!---->
                    <span class="ng-arrow-wrapper">
                        <span class="ng-arrow"></span></span>
                        </div><!----></ng-select>
                        <div _ngcontent-wdj-c58="" class="select-validation">
                            <eld-shared-validation _ngcontent-wdj-c58="" message="Specify delivery time." _nghost-wdj-c55="">
                                <!---->
                                </eld-shared-validation>
                                </div></div></div>

更新:當我使用 selenium Select 時:

a =Select(driver.find_element_by_xpath('/html/body/eld-root/div[2]/div[2]/div/eld-sell-page/div/section/eld-place-offer/div/div/eld-shared-offer-edit-form/form/div[1]/div[1]/div/ng-select'))

我收到錯誤:

UnexpectedTagNameException: Message: Select only works on <select> elements, not on <ng-select>

項目代碼 html 是:

<div class="ng-dropdown-panel-items scroll-host">
<div>
    </div>
    <div>
        <!---->
        <!---->
        <div class="ng-option ng-star-inserted ng-option-marked" role="option" aria-selected="false" id="a67359450338-0">
            <!---->
            <!---->
            <span class="ng-option-label ng-star-inserted">20 min</span>
            </div>
            <div class="ng-option ng-star-inserted" role="option" aria-selected="false" id="a67359450338-1">
                <!---->
                <!---->
                <span class="ng-option-label ng-star-inserted">1 h</span
                ></div>
                <div class="ng-option ng-star-inserted" role="option" aria-selected="false" id="a67359450338-2">
                    <!---->
                    <!----><span class="ng-option-label ng-star-inserted">5 h</span>
                    </div>
                    <div class="ng-option ng-star-inserted" role="option" aria-selected="false" id="a67359450338-3">
                        <!---->
                        <!---->
                        <span class="ng-option-label ng-star-inserted">1 day</span>
                        </div>
                        <div class="ng-option ng-star-inserted" role="option" aria-selected="false" id="a67359450338-4">
                            <!---->
                            <!---->
                            <span class="ng-option-label ng-star-inserted">2 days</span
                            ></div>
                            <div class="ng-option ng-star-inserted" role="option" aria-selected="false" id="a67359450338-5">
                                <!---->
                                <!---->
                                <span class="ng-option-label ng-star-inserted">7 days</span>
                                </div>
                                <div class="ng-option ng-star-inserted" role="option" aria-selected="false" id="a67359450338-6">
                                    <!---->
                                    <!----><span class="ng-option-label ng-star-inserted">28 days</span>
                                    </div>
                                    <!---->
                                    <!---->
                                    <!---->
                                    <!---->
                                    </div>
                                    </div>

我嘗試使用 webdriver ==> Select 或找到元素和 click() 和 send_Keys(something) 但它們不起作用

該網站是https://www.eldorado.gg/並且請參閱 select 框應該是 go 出售,如果可能想在部落沖突中填寫我的情況,然后應該看到檢查一個站點,看看是否 tnx

如異常 Select 中所述,應與<select>標記一起使用。

在您的情況下,沒有 select html 元素,因此您必須使用其他選項,如下所示

deliveryTimeEle = driver.find_element_by_xpath("//ng-select[@formcontrolname ='guaranteedDeliveryTime']//input[@role='combobox']")
# click on the combo list box
deliveryTimeEle.click()

# click on the list option ( you can change the option based on the requirement.
driver.find_element_by_xpath("//div[@role='option'][normalize-space(.)='1 day']").click()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM