单击后隐藏下拉菜单

时间:2020-06-13 16:07:36

标签: javascript python selenium

我正在尝试使用脚本将Sofascore.com网站的语言更改为英语,但是当我执行单击下拉按钮以显示更多语言时,该框会自动隐藏(就像我在框外单击一样)。

我知道这段代码并不优雅,但是由于出现错误“元素不可交互”,我无法以其他方式点击元素(语言)。

        settings = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".fcZZUI")))
        settings.click()
        time.sleep(1)

        lang_icon = driver.find_elements_by_class_name('eTWkgw')[1]
        actions = ActionChains(driver)
        actions.move_to_element_with_offset(lang_icon, 15, 15)
        actions.click()      # this should open menu and it does, but hides instantly
        actions.perform()
        time.sleep(2)

        eng = driver.find_element_by_xpath("//li[@id='downshift-9413607-item-3']")
        pick = ActionChains(driver)
        pick.move_to_element_with_offset(eng, 10, 10)
        pick.click()
        pick.perform()

0 个答案:

没有答案