"Element is not currently visible" when locating element by CssSelector/helptext



  • I faced an issue with locating the element. Currently it's impossible to locate it by CssSelector/helptext, but it's located by CssSelector/Id without issues

    Here's the element

    <span id="ctl08_ctl02_ctl03_ctl01_ctl00_ctl02_ctl06_ctl03_ctl01_ctl02_ctl03_sb0x0" class="dataControl HasHelpText" helptext="Indicate if currently, or within the past 12 months, the client had any long-term care insurance policies or riders (including healthcare service or health maintenance organization contracts) in force or pending."><span class="dataControl HasHelpText">
    

    My code:

    Not working

    [FindsBy(How = How.CssSelector, Using = "span[helptext='Indicate if currently, or within the past 12 months, the client had any long-term care insurance policies or riders (including healthcare service or health maintenance organization contracts) in force or pending.']")]
        private IWebElement ltcQuestion1;
    
    public void click(){
    ltcQuestion1.FindElement(By.CssSelector("input[value='False']")).Click();
    }
    

    This works correctly:

    [FindsBy(How = How.CssSelector, Using = "span[id='ctl08_ctl02_ctl03_ctl01_ctl00_ctl02_ctl06_ctl03_ctl01_ctl02_ctl03_sb0x0']")]
            private IWebElement ltcQuestion1;
    public void click(){
    ltcQuestion1.FindElement(By.CssSelector("input[value='False']")).Click();
    }
    


  • For testing Xpaths and CssSelectors, please open Chrome and its Developer Tools (by pressing F12).

    In the console screen, you can enter the following:

    $x("your xpath here")
    

    or

    $$("your Css selector here")
    

    After pressing Enter, the console will list all elements matching your query. This is the easiest method to test and fix any mistakes in your selectors.

    On a side note: why would you even try finding an element by an elaborate attribute rather than by its ID? If you want to check if the helptext is correct, use an Assert method in your flow.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2