【问题标题】:Python selenium find_element_by_class_name.click not workingPython selenium find_element_by_class_name.click 不起作用
【发布时间】:2021-07-06 16:39:57
【问题描述】:
<button class="in chlodIng" onclick="Attendance.Dashboard.WeeklyData.updateCheckOut(true)">
driver.find_element_by_class_name('out chlodIng').click()

按钮应该被点击,但出现错误:

selenium.common.exceptions.NoSuchElementException: 消息:没有这样的元素:无法找到元素:{"method":"css selector","selector":".out chlodIng"}

请让我知道如何以正确的方式进行操作。提前致谢

【问题讨论】:

  • 我在图片上没有看到与'out chlodIng' 类名匹配的元素

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


【解决方案1】:

类名不适用于spaces,我可能会建议您使用下面的css selectorExplicit waits :

示例代码:

wait = WebDriverWait(driver, 10)
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[onclick^='Attendance.Dashboard.WeeklyData.updateCheckOut']"))).click()

进口:

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

【讨论】:

  • 试过了,我得到了错误 wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[onclick^='Attendance.Dashboard.WeeklyData.updateCheckOut']"))).click()文件“/home/madhuraank/.local/lib/python3.8/site-packages/selenium/webdriver/support/wait.py”,第 80 行,直到引发 TimeoutException(消息、屏幕、堆栈跟踪)selenium.common.exceptions .TimeoutException:消息:
【解决方案2】:

请尝试

driver.find_element_by_xpath("//button[@class='in chlodIng'][contains(.,'Check-in')]

【讨论】:

  • 试过,得到错误:selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法找到元素:{“method”:“xpath”,“selector”:“//button[ @class='in chlodIng'][contains(.,'Check-in')]"}
  • 你能提供你的网址吗
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-26
  • 1970-01-01
  • 1970-01-01
  • 2018-09-30
  • 2017-09-08
  • 1970-01-01
相关资源
最近更新 更多