【问题标题】:send_keys() method of selenium python not working sometimesselenium python的send_keys()方法有时不起作用
【发布时间】:2019-09-17 20:45:55
【问题描述】:

send_keys() selenium python 的方法有时不起作用。我发送的密钥和选择的密钥有时不同。这通常发生在页面加载时间过长时。

我在发送元素的键以加载所有下拉值之前尝试使用睡眠,但这也不起作用。

WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.ID, "Tag")))
sleep(10)
self.driver.find_element_by_id('Tag').send_keys('Key Value')

【问题讨论】:

  • 您使用的是哪个网络驱动(含版本)和浏览器(含版本)?

标签: python-3.x selenium selenium-webdriver webdriver webdriverwait


【解决方案1】:

由于您打算在调用send_keys() 之前使用WebDriverWait 而不是expected_conditions 作为visibility_of_element_located(),您需要使用element_to_be_clickable(),如下所示:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, "Tag"))).send_keys("Key Value")

【讨论】:

  • @DebanjanB 非常感谢
  • 仍然存在选择不同键的问题。有没有其他解决方法来解决这个问题
【解决方案2】:

以下代码有助于选择特定选项,

    select2=WebDriverWait(self.driver, 20).until(EC.visibility_of_element_located((By.ID, "ID_Name")))
    for item2 in select2.find_elements_by_tag_name('option'):
        if item2.text.strip() == 'Option Name':
            item2.click()
            break

【讨论】:

    猜你喜欢
    • 2022-12-18
    • 1970-01-01
    • 1970-01-01
    • 2021-02-01
    • 2016-04-12
    • 2021-02-05
    • 1970-01-01
    • 2022-12-03
    • 1970-01-01
    相关资源
    最近更新 更多