【问题标题】:Issue in locating web element selenium定位 web 元素 selenium 的问题
【发布时间】:2021-03-24 04:23:34
【问题描述】:

我无法在网站上找到 Web 元素,该网站的 Web 元素是动态的,我试图定位的元素具有与其他元素非常相似的属性,只有很小的差异,例如整数变化。当我刷新页面时,这些整数也会发生变化,所以我无法找到有人可以帮忙吗?

我尝试了以下但语法可能有错误:

  1. 包含文本 = WebDriverWait(browser, 15).until(EC.presence_of_element_located( (By.XPATH,"//div[contains(text(),'Type here...')]") ))

  2. Absolute Xpath 和 Rel Xpath(这些变化)

  3. 包含兄弟元素,包含父元素但父元素和兄弟元素也无法定位

这里是元素<div contenteditable="true" class="cke_textarea_inline cke_editable cke_editable_inline cke_contents_ltr placeholder cke_show_borders" tabindex="0" spellcheck="true" role="textbox" aria-label="Rich Text Editor, editor15" title="Rich Text Editor, editor15" aria-describedby="cke_849" style="position: relative;" xpath="1">enter question here</div>的html

【问题讨论】:

  • 请添加html
  • 在这里输入问题
  • @SelectorsHub-TheXPathTool 所以没有空间?

标签: python html selenium automation


【解决方案1】:

添加的空格()有时会导致问题,请删除该空格。另外,如果您可以共享 html,那么我们也许可以提供帮助。 WebDriverWait(browser,15).until(EC.presence_of_element_located((By.XPATH,"//div[contains(text(),'Type here...')]")))

我删除空间不起作用然后你可以在xpath下面尝试-

//div[text()='enter question here'][contains(@aria-label,'Rich Text Editor')]

【讨论】:

    【解决方案2】:

    如果确实没有您认为可靠的属性,您可以通过其中的文本访问该元素。我推荐两件事:除非你找不到其他选择,否则不要这样做,不要只使用 //div,尽可能多地向路径添加 XPATH 信息。

    driver.find_element_by_xpath('//div[text()="enter question here"]')
    

    driver.find_element_by_xpath('//div[contains(text(),"enter question")]')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-11
      • 1970-01-01
      • 2019-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多