如何使用 ng-click 单击 angularjs 启用的元素

How to click on the angularjs enabled element with ng-click

我有以下页面,我需要点击“用户登录”。

我找不到要继续的元素。

<a class="nav-link page-scroll login-a ng-binding" data-toggle="modal" data-target="#loginToast" href="javascript:void(0);" ng-click="vm.showLoginToast({},'login');" ng-class="{'urdu-login-mobile':language==='UR' || language==='ur'}">User Login</a>

元素是Angular element so to click() on the element you have to induce WebDriverWait for the element to be clickable and you can use either of the following :

  • 使用JavacssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.nav-link.page-scroll.login-a.ng-binding[data-toggle='modal'][data-target$='loginToast']"))).click();
    
  • 使用PythonXPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='nav-link page-scroll login-a ng-binding' and @data-toggle='modal'][text()='User Login']"))).click()