如何使用selenium-python定位Angularjs元素 我同意
我尝试了如何使用selenium-python定位Angularjs元素 我同意,python,angularjs,selenium,Python,Angularjs,Selenium,我尝试了Link\u Text,xpath,class。定位器 但是它的投掷 “引发异常\u类(消息、屏幕、堆栈跟踪) selenium.common.exceptions.NoSuchElementException:消息:无此类 元素:找不到元素: 显然,您的选择器(在注释中提供)将无法作为: 不能对复合类名称使用find\u element\u by\u class\u name() 您不能将find\u element\u by\u link\u text()应用于按钮元素(但仅限于a
Link\u Text
,xpath
,class
。定位器
但是它的投掷
“引发异常\u类(消息、屏幕、堆栈跟踪)
selenium.common.exceptions.NoSuchElementException:消息:无此类
元素:找不到元素:
显然,您的选择器(在注释中提供)将无法作为:
- 不能对复合类名称使用
find\u element\u by\u class\u name()
- 您不能将
应用于find\u element\u by\u link\u text()
按钮
元素(但仅限于
)a
<button ng-if="vm.signatureRequired" ng-disabled="!vm.signature || vm.signature.length < 2" type="button" aria-hidden="true" data-ng-click="$hide();vm.isAgreement=true;" class="btn btn-default back_btn ng-scope">I Agree</button>
您可能还需要等待一段时间,直到您的按钮可点击:
driver.find_element_by_xpath('//button[text()="I Agree"]').click()
解决NoTouchElementException
的另一种方法是检查r元素是否位于frame
/iframe
块中。如果是这样,您需要在处理目标元素之前切换到该帧:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
wait = WebDriverWait(driver, 10)
wait.until(EC.element_to_be_clickable((By.XPATH, '//button[text()="I Agree"]'))).click()
显示您已经尝试过的代码1)驱动程序。按类名称(“btn btn默认返回\U btn ng范围”)查找元素。单击()
driver.switch_to_frame('frame_name_or_id')