3

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();
}

closed as unclear what you're asking by Bharat Mane, Michael Durrant, IAmMilinPatel, Kate Paulk, Paul Muir May 9 '16 at 12:17

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

0

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.

-1

Resolved. Quite a newbie error. I should use only firebug to find xPath. Like below

[FindsBy(How = How.XPath, Using = "/html/body/div[1]/form/div[3]/table/tbody/tr[2]/td/table/tbody/tr/td/table/tbody/tr[3]/td/div/span/table/tbody/tr[2]/td/div/div[2]/table/tbody/tr[1]/td/table/tbody/tr[2]/td/div/table/tbody/tr[3]/td/table/tbody/tr/td/table/tbody/tr[2]/td/table/tbody/tr[2]/td/div/table/tbody/tr[2]/td[2]/span[1]")]
        private IWebElement ltcQuestion1;
  • 2
    Could you expand this into a proper answer and then accept it, please? – Kate Paulk May 4 '16 at 15:38
  • 3
    Yes, please elaborate. If it's an error you think people have a high chance of running into, when they google your error message, they will find this page and hopefully your answer will help them. While we're always trying to help the person with the problem, one of the goals of Stack Exchange is to make an expert collection of knowledge for future visitors. Also worth noting, without the explanation of what the fix was, this isn't really an answer, is it? :) – corsiKa May 4 '16 at 16:01
  • Expanded. This is exactly what I used in my code. Thanks fir comment ;) – wrath1888 May 5 '16 at 10:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.