The type or namespace SelectElement could not be found in selenium c#

后端 未结 5 567
没有蜡笔的小新
没有蜡笔的小新 2020-12-07 01:19
driver.FindElement(By.Id(\"inputUsername\")).SendKeys(\"aca\");
driver.FindElement(By.Id(\"inputPassword\")).SendKeys(\"123\");
driver.FindElement(By.TagName(\"butto         


        
相关标签:
5条回答
  • 2020-12-07 01:55

    Selenium WebDriver C# code for selecting item from Drop Down:

    IWebElement selectElement = driver.FindElement(By.Id("selectFilterbyUser"));
    SelectElement oSelect = new SelectElement(selectElement);
    

    There are 3 ways to select drop down item: byText, byIndex, byValue

    1.byText()

    oSelect.SelectByText("Alex");
    

    2.byIndex()

    SelectAnEducation.SelectByIndex(0);
    

    3.byValue()

    SelectAnEducation.SelectByValue("Alex");
    

    Hope this helps,

    0 讨论(0)
  • 2020-12-07 01:56

    First of all, You need to install the proper package from NuGet which is Selenium.Support

    Correct using statements is as:

    using OpenQA.Selenium.Support.UI;

    0 讨论(0)
  • 2020-12-07 02:09

    You need to make sure to reference the NuGet Package Selenium.Support.

    I was having the same issue and then realized that I was only referencing the Selenium.WebDriver NuGet Package. After adding the Selenium.Support NuGet package, and adding the proper using statements. My SelectElement code successfully compiled.

    The proper using statements

    using OpenQA.Selenium;
    using OpenQA.Selenium.Support.UI;
    
    0 讨论(0)
  • 2020-12-07 02:16

    I had the same issue due to using the pre-release version. v4.00 alpha. I installed the previous version v3.141.0 and the errors were resolved

    0 讨论(0)
  • 2020-12-07 02:19

    Referring to a few previous posts it seems if you are using frameworks like nunittestadapter, NUnit.Framework, VS 2017 using the NuGet Manager sometimes there can be issues with the installation /configuration.

    SelectElement Class

    As per the documentation the SelectElement Class is pretty much available within OpenQA.Selenium.Support.UI Namespace which provides a convenience method for manipulating selections of options in an HTML select element.


    Inheritance Hierarchy

    System.Object
        OpenQA.Selenium.Support.UI.SelectElement
    

    Namespace: OpenQA.Selenium.Support.UI


    Assembly: WebDriver.Support (in WebDriver.Support.dll) Version: 3.1.0


    Syntax: public class SelectElement : IWrapsElement


    Snapshot:

    Solution

    Uninstall & reinstall the Selenium.Webdriver and Selenium.Support packages, that will surely fix the problem.

    Reference

    You can find a relevant discussion in Cannot find WebDriverWait class in OpenQa Selenium 3.7

    0 讨论(0)
提交回复
热议问题