【发布时间】: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()
<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>
谢谢
【问题讨论】:
-
请提供minimal reproducible example,以及当前和预期的输出。你做过调试吗?我建议阅读ericlippert.com/2014/03/05/how-to-debug-small-programs。
标签: python css selenium webdriver