【问题标题】:Selenium / Python硒/蟒蛇
【发布时间】:2021-06-28 14:26:39
【问题描述】:

我有这个错误 selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[name="channel-icon-wrapper-2eYxZ"]"}

这里是代码 connexion_bar = driver.find_element_by_name("channel-icon-wrapper-2eYxZ")

这里是代码 HTML <div class="channel-name-2qzLW">Utiliser téléphone/e-mail/nom d'utilisateur</div>

我尝试将connexion_bar = driver.find_element_by_name("channel-icon-wrapper-2eYxZ") 替换为connexion_bar = driver.find_element_by_class_name("channel-icon-wrapper-2eYxZ"),但出现相同的错误消息:/

【问题讨论】:

  • 当您的 HTML 甚至不包含该字符串时,为什么还要坚持按名称或按类别搜索 channel-icon-wrapper-2eYxZ

标签: python selenium xpath css-selectors webdriver


【解决方案1】:

类属性似乎是动态的。要识别元素,请使用以下任一选项

Xpath

driver.find_element_by_xpath("//div[contains(@class,'channel-name-')]")

driver.find_element_by_xpath("//div[text()='Utiliser téléphone/e-mail/nom d'utilisateur']")

CSS 选择器

driver.find_element_by_css_selector("div[class^='channel-name']")

【讨论】:

  • 完美!感谢您的帮助!
猜你喜欢
  • 2016-05-28
  • 2021-07-07
  • 2023-02-06
  • 1970-01-01
  • 2021-10-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-06
相关资源
最近更新 更多