【问题标题】:selenium create a delay before selecting button by nameselenium 在按名称选择按钮之前创建延迟
【发布时间】:2021-07-27 12:24:50
【问题描述】:

我想定位一个包含名称“loginButton”的按钮,并在加载后单击元素等,这样它就不会单击加载微调器。我该如何处理这个以 name 元素为目标的 webdriverwait?

from selenium.webdriver.support.wait import WebDriverWait 
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((find_element_by_name('loginButton'), "loginButton"))).click()

【问题讨论】:

  • 如果不能点击它就不点击它...如果延迟是固定的你可以使用time.sleep(yourdelay)函数。
  • 它是一个按钮,所以它肯定会点击,问题是我该如何处理 webdriverwait 延迟?我的代码正确吗?
  • 这能回答你的问题吗? Selenium wait for element to be clickable python
  • 先知有答案!

标签: python selenium selenium-webdriver


【解决方案1】:

你几乎是对的。
对于提供的示例,请尝试使用以下代码:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

element = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.NAME, "loginButton")))

element.click();

更多解释请见here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-18
    • 1970-01-01
    相关资源
    最近更新 更多