在Selenium Python中,是否可以选择只有类值的按钮? html如下:
<button class="secondary option-action ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false"
from selenium import webdriver
browser = webdriver.Firefox()
browser.get(any_url)
你想选那个按钮吗?
是的,这是可能的。
使用^{} (或
find_elements_by_class_name
获取多个匹配元素):也可以使用^{} (或..s变量):
或者,您也可以使用
find_element_by_xpath
,但它需要详细的xpath表达式才能精确:您可以使用css选择器:
多个类:
您还可以使用:
如果有多个具有相同类的按钮,则可以执行以下操作:
如果您只使用类,那么页面中很可能会有另一个具有相同类的按钮,因此有时您必须更具体
我会给你一个和我之前给你的问题类似的答案:
不过,您必须自己填写
...
,或者使用:如果没有任何其他
input
元素的class
属性以“secondary option”开头。。。相关问题 更多 >
编程相关推荐