1

Here is my control:

<input name="ctl00$ContentMain$dockAlert$C$ucAlerts$ddlViewBy" type="text" class="rcbInput radPreventDecorate" id="ctl00_ContentMain_dockAlert_C_ucAlerts_ddlViewBy_Input" value="Active" readonly="readonly" autocomplete="off">

Here is how I am TRYING to access it: (tried all 3)

SelectElement ddlViewBy = new SelectElement(driver.FindElement(By.Name("ddlViewBy")));
SelectElement ddlViewBy = new SelectElement(driver.FindElement(By.Id("ddlViewBy")));
SelectElement ddlViewBy = new SelectElement(driver.FindElement(By.Id("ctl00_ContentMain_dockAlert_C_ucAlerts_ddlViewBy_Input")));

I must be missing something simple.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Mark
  • 21
  • 4

1 Answers1

0

The desired WebElement is a dynamic element, so to identify the element you have to induce WebDriverWait for the ElementIsVisible() and you can use either of the following Locator Strategies:

  • CssSelector:

    SelectElement ddlViewBy = new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementIsVisible(By.CssSelector("input.rcbInput.radPreventDecorate#ctl00_ContentMain_dockAlert_C_ucAlerts_ddlViewBy_Input")));
    
  • XPath:

    SelectElement ddlViewBy = new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementIsVisible(By.XPath("//input[@id='ctl00_ContentMain_dockAlert_C_ucAlerts_ddlViewBy_Input' and @class='rcbInput radPreventDecorate']")));
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Sorry, I meant to add this as well - your line is angry with what I have. Thanks for the quick answer :) – Mark Jan 15 '22 at 21:12
  • Those lines aren't part of your question as well :) – undetected Selenium Jan 15 '22 at 21:14
  • Sorry, I was late adding them. – Mark Jan 15 '22 at 21:33
  • @Mark Please don't change the question based on which you have received well researched answers. Once you receive canonical answers changing the question can make all the existing answers invalid and may not be useful to future readers. If your requirement have changed feel free to raise a new question. StackOverflow contributors will be happy to help you out. For the time being I have reverted back the question to it's initial state. – undetected Selenium Jan 15 '22 at 21:35
  • I was trying to add more code that I forgot to add but I couldn't add it here. – Mark Jan 15 '22 at 21:36
  • As per your initial question the error was identifying the `` element. But now you are saying error happens even before that. – undetected Selenium Jan 15 '22 at 21:38
  • I am trying to get to the input element, yes. I missed code that pertained to my initial question. – Mark Jan 15 '22 at 21:39
  • But your question was related to the ` element, but not what code was used before that line, agree? – undetected Selenium Jan 15 '22 at 21:41
  • yes.. ill repost with the full question this time. – Mark Jan 15 '22 at 22:03