如何使用Selenium和python编程在亚马逊中处理没有iframe的“邮政编码”窗口弹出窗口

问题描述

我几乎尝试使用编程语言与弹出窗口相关的所有代码都是python编码和selenium,但它们都没有在邮政编码中使用send.key("XXXXX")命令。因为它们大多与页面代码中的 iframe 相关,所以它处理窗口 switch_to.frame()switch_to.window。在我的情况下,页面代码中没有 iframe 并且弹出窗口不会在该输入邮政编码中发送密钥。所以我需要帮助来处理这些类型的窗口弹出 python 和 selenium 编程来处理弹出窗口。

driver.switch_to.frame()
driver.switch_to.window()
driver.switch_to.alert()


    browser.get('www.amazon.com')
        browser.find_element_by_xpath("""//*[@id="nav-global-location-popover-link"]""").click()
        browser.set_page_load_timeout(1000)
        browser.switch_to.active_element()
        browser.find_element_by_xpath('//*[@id="gluXZipUpdateInput"]').send_keys("85224")

解决方法

您需要点击交货地点栏并以编程方式设置PIN码,如下图

loc = str(driver.find_element_by_id("glow-ingress-line2").text).strip().replace(" ","")
        if loc == "India" in driver.page_source:
            WebDriverWait(driver,30).until(
                EC.presence_of_element_located((By.ID,"nav-packard-glow-loc-icon")))
            driver.find_element_by_id("nav-packard-glow-loc-icon").click()
            WebDriverWait(driver,"GLUXZipUpdateInput")))
            driver.find_element_by_id("GLUXZipUpdateInput").send_keys(10001)

            ActionChains(driver).send_keys(Keys.SHIFT,Keys.ENTER).perform()

            WebDriverWait(driver,"GLUXConfirmClose")))
            driver.refresh()