Как нажимать на кнопку (angular) через python script selenium

Я новичок в selenium, python и angular. Мне удалось провести несколько тестов с Python и селеном; однако мне трудно щелкнуть по кнопке, когда задействован angularJS. Код кнопки:

<button type="button" ng-click="validateList()" id="home-xyz-button">
 Validate
</button>

Я запускаю код:

browser.find_element_by_id("home-xyz-button").click()

и это не сработает.

1 ответ

Ниже мой script:

import os, sys
from selenium import webdriver
# Load the firefox driver
browser = webdriver.Firefox()
# Open a browser and browser to website 
browser.get('link to the website')
browser.implicitly_wait(10)
# Select File for Validation
SelectFileForValidation = browser
 .find_element_by_xpath("//div[@class=\"row ng-scope\"]"+
 "/div/div/table/tbody/tr[1]/td[1]/input")
if SelectFileForValidation is None:
 print('SelectFileForValidation is not found')
 exit(0)
else:
 print('SelectFileForValidation is found')
 SelectFileForValidation.click()
# Get the file name
FindTheUploadedFile = browser.find_element_by_xpath("//div[@class=\"row ng-scope\"]/div/div/table/tbody/tr[1]/td[3]/div[@class=\"ng-binding\"]")
if FindTheUploadedFile is None:
 print('FindTheUploadedFile is not found')
 exit(0)
else:
 print('FindTheUploadedFile is found')
 print FindTheUploadedFile.text 
ValidateFileButton = browser.find_element_by_xpath("//button[@id=\"home-xyz-button\"]")
if ValidateFileButton is None:
 print('ValidateFileButton is not found')
 exit(0)
else:
 print('ValidateFileButton is found')
 ValidateFileButton.ng-click()
#browser.get('link to the site (used to refresh)')
exit(0)

Код HTML:

<div>
 <button type="button" data-toggle="modal" data-target="#uploadFileModal" id="kkk">
  Upload
 </button>
 <button type="button" ng-click="validateList()" id="home-xyz-button">
  Validate
 </button>
 <button disabled="true" type="button" id="aaaa">
  Download
 </button>
 <button disabled="true" type="button" id="bbbb">
  Delete
 </button>
 <!-- Modal -->
 <div id="cccc" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
 <div>
 <div>
 <div>
 <button type="button" data-dismiss="modal" aria-hidden="true">×</button>
 <h2 id="dddd">Upload File</h2>
 </div>
 <div>
 Browse to the file you intend to upload.  
  
 
 <button type="button" data-dismiss="modal" id="ggg">Close</button>
 <button type="submit" id="hhh" ng-click="uploadFile()">Upload</button>
 </div>
 </div>
 </div>
 </div>
 <!-- End Modal -->
</div>

Распечатка, которую я получаю:

SelectFileForValidation is found
FindTheUploadedFile is found
"The file Name"
ValidateFileButton is found

Но я не вижу, что выполняется клик()

licensed under cc by-sa 3.0 with attribution.