【问题标题】:Select class with selenium python使用 selenium python 选择类
【发布时间】:2020-11-03 21:34:14
【问题描述】:

您好,我正在尝试使用 selenium、python 和 GLPI 自动化流程,但最近我花了很多时间尝试选择菜单栏的用户,我已经使用 linkText、cssSelector、xpath 进行了测试,但没有一个有效对我来说,也许我做错了,感谢您的帮助。

driver.find_element_by_xpath("//a[contains(@href,'javascript:void(0)') and contains(.,'select2-choice')]").click()
driver.find_element_by_css_selector("a[href*='select2-container select2-container-active select2-dropdown-open']").click()
driver.find_element_by_link_text("javascript:void(0)").click()

https://ibb.co/RbrXDrv即代码源

<div class="select2-container select2-container-active select2-dropdown-open" id="s2id_dropdown__users_id_requester722037505" style="width: 80%;"><a href="javascript:void(0)" class="select2-choice" tabindex="-1">   <span class="select2-chosen" id="select2-chosen-4">-----</span><abbr class="select2-search-choice-close"></abbr>   <span class="select2-arrow" role="presentation"><b role="presentation"></b></span></a><label for="s2id_autogen4" class="select2-offscreen"></label><input class="select2-focusser select2-offscreen" type="text" aria-haspopup="true" role="button" aria-labelledby="select2-chosen-4" id="s2id_autogen4" disabled=""></div>

谢谢

【问题讨论】:

标签: python css selenium webdriver


【解决方案1】:

您的 xpath 不正确。

试试这个:

driver.find_element_by_xpath("//a[@href='javascript:void(0)' and @class='select2-choice']").click()

顺便说一句,最好提供url或html,而不是图片。

【讨论】:

  • 您好,感谢您的回答,我尝试了该代码,但仍然无法正常工作,我放了源代码
猜你喜欢
  • 2021-08-26
  • 2011-11-23
  • 2021-12-27
  • 1970-01-01
  • 2014-04-27
  • 2014-02-08
  • 2018-08-04
  • 1970-01-01
  • 2021-03-28
相关资源
最近更新 更多