gpt4 book ai didi

python-3.x - Selenium 网络驱动程序 : list all elements of "input" drop down and select a different element

转载 作者:行者123 更新时间:2023-12-03 16:49:42 25 4
gpt4 key购买 nike

使用 python3 Selenium ChromeDriver,在这个 URL 上:

https://www2.sgx.com/derivatives/products/chinaa50

  • 如何获取合约月份列表。从 Chrome F12 看来,这是相应的 HTML。
    <sgx-input-select class="sgx-input" name="" label="" hint="" message=""
    placeholder="">
    <span class="sgx-input-hint-icon" style="visibility: hidden;"></span>
    <span class="sgx-input-hint"></span>
    <label class="sgx-input-select-label">
    <span
    class="sgx-input-label" style="display: none;"></span><span
    class="sgx-input-select-filter-wrapper"><input
    is="sgx-select-filter" type="text"
    class="sgx-input-control sgx-input-select-filter" name=""
    placeholder="" readonly="">
    <span
    class="sgx-select-filter-icon" title=""></span>
    </span>
    </label>
    <div class="sgx-input-message" style="display: none;"></div>
    <sgx-select-model style="display: none;"></sgx-select-model>
    </sgx-input-select>
  • 如何从列表中选择不同的元素,从而导致相邻小部件重新加载?

  • 下拉列表的 XPath 似乎是:
    //*[@id="page-container"]/template-base/div/div/section[1]/div/sgx-widgets-wrapper/widget-derivatives-prices-and-chart/div[1]/div/div[2]/sgx-input-select

    有没有更好的 XPath 来引用它?

    最佳答案

    Contract Month 的更易读的 Xpath下拉将是

    //div[text()='Contract Month']//following-sibling::sgx-input-select//input
    Contract Month 的 CSS 选择器下拉 options
    .sgx-select-picker-list .sgx-select-picker-option label .sgx-select-picker-label

    你给了点击联系月份下拉菜单,然后找到 options使用上述标识符。然后你可以点击选项

    伪代码:
    # Adding implicit wait 
    driver.implicitly_wait(10)

    # Page has ajax loading where the dropdown loads slowly
    # Adding sleep now. This has to be handled by webdriver wait
    time.sleep(10)
    dropdown = driver.find_element_by_xpath("//div[text()='Contract Month']//following-sibling::sgx-input-select//input")
    # On clicking the dropdown, the options loads
    dropdown.click();
    options = driver.find_elements_by_css_selector(".sgx-select-picker-list .sgx-select-picker-option label .sgx-select-picker-label")

    optionSize = len(options);

    for index in range(optionSize - 1):
    dropdown.click();
    # Find the options again as click on Month will reset the options
    options = driver.find_elements_by_css_selector(".sgx-select-picker-list .sgx-select-picker-option label .sgx-select-picker-label")
    options.index(index).click()

    # Page has ajax loading where the dropdown loads slowly
    # Adding sleep now. This has to be handled by webdriver wait
    time.sleep(10)

    关于python-3.x - Selenium 网络驱动程序 : list all elements of "input" drop down and select a different element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56201116/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com