Question

The page i am automating has a dxheViewArea. I want to enter some text in this field.

My Webdriver code is:

d.FindElement(By.CssSelector(".dxheDesignViewArea dxheViewArea")).SendKeys("Who invented the first fixed witn aircraft?"); 

I run it in NUnit, the error returned is Unable to locate element: {"method":"css selector","selector":".dxheDesignViewArea dxheViewArea"}

In Firefox i inspect the element, the code is:

<body class="dxheDesignViewArea dxheViewArea" style="border-width: 0px;" spellcheck="false"/>

What Xpath syntax can i use to locate and enter some text in this element please?

Full source is here:

        <style/>
        <link href="/DXR.axd?r=4_1" type="text/css" rel="stylesheet"/>
        <style charset="utf-8" type="text/css">xxxxxxxx</style>
        <style id="firepath-matching-node-style" type="text/css">.firepath-matching-node      { outline: 2px dashed #00F;}</style>
    </head>
    <body class="dxheDesignViewArea dxheViewArea" style="border-width: 0px;"             spellcheck="false"/>
</html>
Was it helpful?

Solution 5

I have finally managed to get it work now. It was in an iFrame. Here is the code i used.

IWebElement iframe = driver.FindElement(By.Id("ctl00_uxContentPlaceHolderContent_uxQuestionHTMLTextEditor_uxQuestionHTMLTextEditor_editor_DesignIFrame"));
        driver.SwitchTo().Frame(iframe);
        driver.FindElement(By.XPath("//body[@class='dxheDesignViewArea dxheViewArea']")).SendKeys("Who invented the first fixed wing aircraft?");
        driver.SwitchTo().DefaultContent(); 

OTHER TIPS

You should qualify both CSS classes as classes. What you did is only the first one. Try this:

d.FindElement(By.CssSelector(".dxheDesignViewArea.dxheViewArea")).SendKeys("Who invented the first fixed witn aircraft?");

I think You should locate the WebElement that contains the specified field:

WebElement container = driver.findElement(By....); // locate the WebElement that contains the input field.... by cssselector or xpath
container.findElement(By.xpath("//*[@class='dxheDesignViewArea dxheViewArea']")).SendKeys("Who invented the first fixed witn aircraft?");

UPDATE: It is not so easy without the complete html code but I found the driver.switchTo() method:

WebElement iframe = driver.findElement(By.xpath("//*[@id='...']")) // locate the iframe
driver.switchTo().frame(iframe);
.... // find elements
driver.switchTo().defaultContent();

References:

Try this

driver.findElement(By.className("dxheDesignViewArea dxheViewArea")).sendKeys("Who invented the first fixed witn aircraft?");

I have been trying the suggestions but still not successful. I have inspected more of the code and notice there is an iFrame. It is because of the iFrame it is not able to locate the element.

Below is the code snippet. What Xpath can i use now to locate class="dxheDesignViewArea dxheViewArea"

<iframe id="ctl00_uxContentPlaceHolderContent_uxQuestionHTMLTextEditor_uxQuestionHTMLTextEditor_editor_DesignIFrame" class="dxheDesignViewArea dxheViewArea" frameborder="0" style="height: 100%; width: 100%; padding: 0px; border-style: none; border-width: 0px;" src="javascript:false" name="ctl00_uxContentPlaceHolderContent_uxQuestionHTMLTextEditor_uxQuestionHTMLTextEditor_editor_DesignIFrame">

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top