Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello all I have a select where it was binded as follows in UI

<div class="choices form-group form-choices" data-type="select-one" dir="ltr" tabindex="-1" role="listbox" aria-haspopup="true" aria-expanded="false">
 <div class="form-control ui fluid selection dropdown" tabindex="0">
  <select lang="en" class="form-control choices__input" type="text" name="data[serviceAmpsDelivered]" ref="selectContainer" dir="ltr" hidden="" tabindex="-1" data-choice="active">
   <option value="6"><span>60</span></option>
  </select>
  <div class="choices__list choices__list--single">
   <div class="choices__item choices__item--selectable" data-item="" data-id="38" data-value="6" data-custom-properties="null" aria-selected="true" data-deletable="">
    <span>60</span>
    <button type="button" class="choices__button" aria-label="Remove item: '6'" data-button="">Remove item</button>
   </div>
  </div>
 </div>
 <div class="choices__list choices__list--dropdown" aria-expanded="false">
  <div class="choices__list" role="listbox">
   <div id="choices--data-oa-item-choice-1" class="choices__item choices__item--choice choices__item--selectable is-highlighted" role="option" data-choice="" data-id="1" data-value="1" data-select-text="" data-choice-selectable="" aria-selected="true">
    <span>50</span>
   </div>
   <div id="choices--data-oa-item-choice-2" class="choices__item choices__item--choice choices__item--selectable " role="option" data-choice="" data-id="2" data-value="6" data-select-text="" data-choice-selectable="">
    <span>60</span>
   </div>
   <div id="choices--data-oa-item-choice-3" class="choices__item choices__item--choice choices__item--selectable " role="option" data-choice="" data-id="3" data-value="2" data-select-text="" data-choice-selectable="">
    <span>100</span>
   </div>
   <div id="choices--data-oa-item-choice-4" class="choices__item choices__item--choice choices__item--selectable " role="option" data-choice="" data-id="4" data-value="5" data-select-text="" data-choice-selectable="">
    <span>150</span>
   </div>
   <div id="choices--data-oa-item-choice-5" class="choices__item choices__item--choice choices__item--selectable " role="option" data-choice="" data-id="5" data-value="3" data-select-text="" data-choice-selectable="">
    <span>200</span>
   </div>
   <div id="choices--data-oa-item-choice-6" class="choices__item choices__item--choice choices__item--selectable " role="option" data-choice="" data-id="6" data-value="4" data-select-text="" data-choice-selectable="">
    <span>400</span>
   </div>
  </div>
 </div>


I am able to select the div and the dropdown gets opened but I am unable to select the item

WebElement srvcAmpsDelivered = (WebElement)driver.FindElement(By.XPath("//select[contains(@name,'data[serviceAmpsDelivered]')]"));
            Helper.JavaScriptClick(driver, srvcAmpsDelivered);


but unable to choose the items which is inside div. This way it works but if I want to change the value I have to code it N times

What I have tried:

Actions act = new Actions(_driver); act.SendKeys(Keys.Down).Perform(); act.SendKeys(Keys.Down).Perform(); Thread.Sleep(1000); act.SendKeys(Keys.Enter).Perform();`
Posted
Updated 15-Mar-23 3:58am

I did a quick google search: Selenium C# select an element inside div[^] and the first result was this: Selenium C# select an element inside div[^]. If not that ine, there are more answers for you
 
Share this answer
 
Comments
demouser743 14-Mar-23 4:58am    
Hi Graeme_Grant I tried those options but didn't worked
Graeme_Grant 14-Mar-23 5:07am    
All of them? Try manually using a CSS style selector to set the color of the element to check that you have it right.
demouser743 14-Mar-23 5:55am    
Yes the problem the binding of dropdown is a bit different, if you look at the HTML it reads the options from div and adding it to select. Not sure what was the back end code behind this but I am unable to select the respective value
OK I got the solution after some trail and errors
WebElement ddlControl= (WebElement)_driver.FindElement(By.XPath("//select[contains(@name,'controlName"));
Helper.JavaScriptClick(_driver, ddlControl);
TimeSpan timeToWait = new TimeSpan(0, 0, 10);
WebDriverWait waitForElemet = new WebDriverWait(_driver, timeToWait);
waitForElemet.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//div[contains(@id,'ControlId')]//following::span[text()='50']"))).Click();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900