Dropdown Selenium C #

0

I'm trying to select a dropdown with selenium C #, but as we can see in the HTML below there is no "ID" or "Name", below the code how am I doing, could you help me?

<select ng-model="vm.activeWhatsapp.channel_id" 
                    ng-options="channel.id as channel.display_name group by channel.sector.name for channel in vm.whatsappChannels" 
                    class="ng-pristine ng-valid ng-empty ng-touched">
                    <option value="?" selected="selected">
                    </option>
                    <optgroup label="Itaú Cartões Ativo">
                    <option label="Liderança - Itaú Cartões Ativo" value="number:1325">Liderança - Itaú Cartões Ativo</option>
                    </optgroup>
                    </select>




    //Selecting a drop down control
    public static  void SelectDropDown(IWebDriver driver, string element, string value, string elementtype)
    {

        if (elementtype == "Id")
            new SelectElement(driver.FindElement(By.Id(element))).SelectByText(value);
        if (elementtype == "Name")
            new SelectElement(driver.FindElement(By.Name(element))).SelectByText(value);
        if (elementtype == "Class")
            new SelectElement(driver.FindElement(By.CssSelector(element))).SelectByValue(value);

SeleniumSetMethods.SelectDropDown(drive, ".ng-pristine.ng-valid.ng-empty.ng-touched", "1325", "Class");
    
asked by anonymous 25.05.2018 / 03:47

3 answers

0

You can access via classPath. Use F12 and follow this structure here:

//*[@<elemento desejado, pode ser id, name etc>='nome']<caminho ex:/tbody/tr> //*[contains(text(),'<texto que se encontra na tag>')] 

If you have any questions, please let me know.

    
01.06.2018 / 22:23
0

I do not know what to do, but I do not have an ID or a name, so I usually use Xpath from Selenium to get the value it goes directly to the tag, see if the example below helps:

SelectElement Selec_Event = new SelectElement(itauPednO9.FindElement(By.Xpath("//*[@id="navbar"]/ul/li[3]/a")));
                Selec_Event.SelectByText(value);

See what's next

Atte!

    
05.06.2018 / 22:24
-1

You can find an element in various ways in Selenium. Particularly when there is no ID, or NAME, or when the ID or NAME are duplicates, I prefer to use CSS Selector, because I find it more "understandable" than Xpath.

But for both CSS and Xpath there is an interesting feature in Chrome. When you press F12 , inspect the element you want to get the data, right-click, go to Copy and select the desired (CSS Selector or XPath)

    
04.12.2018 / 17:28