Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.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
Angularjs 无法使用Selenium选择md select下拉选项_Angularjs_Python 3.x_Selenium_Material Design_Angular Material - Fatal编程技术网

Angularjs 无法使用Selenium选择md select下拉选项

Angularjs 无法使用Selenium选择md select下拉选项,angularjs,python-3.x,selenium,material-design,angular-material,Angularjs,Python 3.x,Selenium,Material Design,Angular Material,我有一个带有一组选项的“角度材质”下拉列表,我正在尝试选择其中一个选项。我选择它们如下: html文件: <md-select name="myDropdown" ng-model="addCompany.details.someModel" ng-change="addCompany.swapDisplayedAreas()" required> <md-option value="Company A

我有一个带有一组选项的“角度材质”下拉列表,我正在尝试选择其中一个选项。我选择它们如下:

html文件:

<md-select name="myDropdown"
           ng-model="addCompany.details.someModel"
           ng-change="addCompany.swapDisplayedAreas()"
           required>

    <md-option value="Company A">Company A</md-option>
    <md-option value="Company B">Company B</md-option>
</md-select>
但是,无论我如何尝试选择该选项,都会出现以下错误:

selenium.common.exceptions.WebDriverException:消息:元素不存在 可在点750423处单击。其他元素将收到单击:

或者我可以看到元素被点击,但下拉列表仍然保持拉出状态。当下拉列表仍被拉出时,尝试单击页面上的任何其他元素会出现类似的md背景,将收到单击错误

知道如何为md select元素选择下拉选择吗?我已尝试为我的输入元素禁用md Background,但没有成功。

您应该尝试使用WebDriverWait,等待从下拉列表中打开选项并使其可见并可单击,然后单击,如下所示:-

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

#find dropdown and click to open options 
input = self.browser.find_element_by_name('myDropdown')
input.click()

#now wait until options getting visible and clickable 
choice = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "md-option[value = 'Company A']")))
choice.click()
您应该尝试使用WebDriverWait等待选项从下拉列表中打开并显示并可单击,然后单击,如下所示:-

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

#find dropdown and click to open options 
input = self.browser.find_element_by_name('myDropdown')
input.click()

#now wait until options getting visible and clickable 
choice = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "md-option[value = 'Company A']")))
choice.click()

我猜问题可能是以下之一:

页面上还有另一个元素,其文本为Company A,并且该元素正试图被单击,即使下拉选项显然是您希望selenium单击的元素。这是因为selenium单击满足标识符的第一个元素。为了检查这是否是问题所在,我将使用find元素并检查找到了多少元素。如果这是问题所在,请尝试使用css选择器,例如value

如果您使用的是chrome,我在测试angular应用程序时遇到了chrome webdriver的类似问题

这就是问题所在 我尝试了一些优雅的解决方法,但没有任何效果…最后我使用了Lukeis的解决方案

在爪哇

int n=10;
    String errorMessage;
    for (int i=1; i<=n; i++)
    {
        try {
            clickThis.click();
            break;
        } catch(WebDriverException driverException) {
            Thread.sleep(1000);
            errorMessage = driverException.toString();
        }
        if(i==n)
        {
            Assert.fail("Failed to click "+n+" times \n" + errorMessage);
        }
    }

它几乎尝试单击元素10次。

我猜问题可能是以下之一:

页面上还有另一个元素,其文本为Company A,并且该元素正试图被单击,即使下拉选项显然是您希望selenium单击的元素。这是因为selenium单击满足标识符的第一个元素。为了检查这是否是问题所在,我将使用find元素并检查找到了多少元素。如果这是问题所在,请尝试使用css选择器,例如value

如果您使用的是chrome,我在测试angular应用程序时遇到了chrome webdriver的类似问题

这就是问题所在 我尝试了一些优雅的解决方法,但没有任何效果…最后我使用了Lukeis的解决方案

在爪哇

int n=10;
    String errorMessage;
    for (int i=1; i<=n; i++)
    {
        try {
            clickThis.click();
            break;
        } catch(WebDriverException driverException) {
            Thread.sleep(1000);
            errorMessage = driverException.toString();
        }
        if(i==n)
        {
            Assert.fail("Failed to click "+n+" times \n" + errorMessage);
        }
    }

它几乎尝试点击元素10次。

您是在Chrome上运行此功能吗?不是,使用Firefox。您是在Chrome上运行此功能吗?不是,使用Firefox。