Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用selenium-python定位Angularjs元素 我同意_Python_Angularjs_Selenium - Fatal编程技术网

如何使用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')