【问题标题】:Find Button element by text按文本查找 Button 元素
【发布时间】:2018-02-06 09:19:01
【问题描述】:
<button aria-label="Connect with ABC" class="search-result__actions--primary button-secondary-medium m5" data-ember-action="" data-ember-action-1510="1510">Connect</button>

<button aria-label="Connect with DEF" class="search-result__actions--primary button-secondary-medium m5" data-ember-action="" data-ember-action-1467="1467">Invite Sent !</button>

我正在尝试使用

查找带有文本“连接”的按钮
connect_buttons = firefox.find_elements_by_link_text ('Connect')

但是firefox找不到按钮。

即使我尝试过使用以下模式,但是

firefox.find_elements_by_xpath("//*[contains(text(), 'Connect')]")
# Not accurate results

firefox.find_elements_by_css_selector('.search-result__actions--primary.button-secondary-medium.m5'); 
# return all button with same css even which doesn't have text "Connect".

请提出建议。

【问题讨论】:

  • 感谢 Vadim 格式化我的问题。 :)
  • 元素是否在 IFRAME 中?

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


【解决方案1】:

您应该尝试使用relative xpath。试试下面的代码,如果你剩下的代码是正确的,它应该可以工作

.//*[@class='search-result__actions--primary button-secondary-medium m5']//*[text()='Connect']

【讨论】:

  • 我尝试使用相对 xpath 但无法返回结果。
猜你喜欢
  • 2011-11-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-26
  • 2020-06-15
  • 2019-11-18
  • 1970-01-01
相关资源
最近更新 更多