Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.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
Python 如何在Selenium中单击角度下拉菜单_Python_Angularjs_Selenium Webdriver - Fatal编程技术网

Python 如何在Selenium中单击角度下拉菜单

Python 如何在Selenium中单击角度下拉菜单,python,angularjs,selenium-webdriver,Python,Angularjs,Selenium Webdriver,我试图使用python selenium在网站上自动生成一些报告,但是由于javascript的原因,我很难确定需要在页面上单击的元素。在firefox中,当我检查元素时,有一个DOM事件图标。我尝试了很多变体,包括xpath等,但没有成功 <account-groups ng-if="EventsList.ToggleService.accountGroup();"> <button class="btn-default" ng-disabled="AccountGroups

我试图使用python selenium在网站上自动生成一些报告,但是由于javascript的原因,我很难确定需要在页面上单击的元素。在firefox中,当我检查元素时,有一个DOM事件图标。我尝试了很多变体,包括xpath等,但没有成功

<account-groups ng-if="EventsList.ToggleService.accountGroup();">
<button class="btn-default" ng-disabled="AccountGroupsCtrl.isDisabled()" ng-click="AccountGroupsCtrl.toggleFlyout()">
</button>
</account-groups>


编辑对于任何查看此文件的人来说,问题是因为我没有使用driver.switch\u to.frame(“frame\u name”)切换帧。执行此步骤后,下面的其余解决方案将用于识别元素。谢谢

您可以使用以下代码从下拉列表中进行选择

from selenium.webdriver.support.ui import Select

select = Select(driver.find_element_by_id('*****'))
select.select_by_visible_text('****')

根据您共享的HTML,不清楚WebElement是否为下拉列表。但是,由于所需元素是要在该元素上调用的元素,因此需要诱导WebDriverWait,并且可以使用以下任一解决方案:

  • CSS\u选择器

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.btn-default[ng-click^='AccountGroupsCtrl']"))).click()
    
  • XPATH

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='btn-default' and starts-with(@ng-click,'AccountGroupsCtrl')]"))).click()
    
注意:您必须添加以下导入:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

@NikBro您需要使用您正试图自动执行的确切手动步骤以及reveant HTML、您的代码试用和错误堆栈跟踪(如果有)来更新问题。这适用于基本HTML选择类型,因为这是angular(ng select)类型。