如何通过python脚本selenium单击按钮(角度)

use*_*549 5 python selenium angularjs

我是硒,蟒蛇和棱角分明的新手.我设法用Python和selenium运行了一些测试; 但是,当涉及angularJS时,我发现很难点击按钮.按钮的代码是:

<button type="button"
        class="xyz"
        ng-click="validateList()"
        id="home-xyz-button">
  <i class="xyz-up"></i>Validate
</button>
Run Code Online (Sandbox Code Playgroud)

我运行代码:

browser.find_element_by_id("home-xyz-button").click()
Run Code Online (Sandbox Code Playgroud)

这不起作用.

use*_*549 -1

下面是我的脚本:

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

HTML 代码是:

\n\n
<div class="111">\n    <button type="button" class="222" data-toggle="modal" data-target="#uploadFileModal" id="kkk">\n        <i class="333"></i> Upload\n    </button>\n    <button type="button" class="xyz" ng-click="validateList()" id="home-xyz-button">\n        <i class="xyz-up"></i> Validate\n    </button>\n    <button disabled="true" type="button" class="444" id="aaaa">\n        <i class="555"></i> Download\n    </button>\n    <button disabled="true" type="button" class="666" id="bbbb">\n        <i class="777"></i> Delete\n    </button>\n    <!-- Modal -->\n    <div class="888" id="cccc" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">\n        <div class="999">\n            <div class="101010">\n                <div class="11111">\n                    <button type="button" class="121212" data-dismiss="modal" aria-hidden="true">\xc3\x97</button>\n                    <h2 class="131313" id="dddd">Upload File</h2>\n                </div>\n                <div class="141414">\n                    Browse to the file you intend to upload. <br> <br>\n                    <input type="file" name="file" id="eee" onchange="angular.element(this).scope().storeFile(this)"> <br>\n                    <input type="checkbox" id="fff> Overwrite existing file\n                </div>\n                <div class="151515">\n                    <button type="button" class="161616" data-dismiss="modal" id="ggg">Close</button>\n                    <button type="submit" class="171717" id="hhh" ng-click="uploadFile()">Upload</button>\n                </div>\n            </div>\n        </div>\n    </div>\n    <!-- End Modal -->\n</div>\n
Run Code Online (Sandbox Code Playgroud)\n\n

我得到的打印输出是:

\n\n
SelectFileForValidation is found\nFindTheUploadedFile is found\n"The file Name"\nValidateFileButton is found\n
Run Code Online (Sandbox Code Playgroud)\n\n

但我看不到 click() 正在执行

\n