2014-05-05 47 views
0

我自动化的页面有dxheViewArea。我想在此字段中输入一些文字。Webdriver找不到dxheViewArea的正确xpath

我webdriver的代码是:

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

我在NUnit的运行,返回的错误是无法找到的元素:{"method":"css selector","selector":".dxheDesignViewArea dxheViewArea"}

在Firefox我检查元素,代码:

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

可以使用什么Xpath语法来定位并在此元素中输入一些文本?

完整的源是在这里:

 <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> 
+0

你用C#吧? –

回答

0

我终于设法得到它现在的工作。它在一个iFrame中。这是我使用的代码。

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

试试这个

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

这不起作用。我想这是因为它在桌子里面。我设法检查周围的元素和源如下:

+0

也有另一种表:

+0

这是混淆现在嘿 –

2

你应该既符合CSS类为类。你做的只是第一个。试试这个:

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

我想你应该找到包含指定字段的WebElement:

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:这也不是没有完整的HTML代码,这样容易,但我发现司机。 SWITCHTO()方法:

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

参考文献:

0

我一直在努力的建议,但仍然没有成功。 我检查了更多的代码,并注意到有一个iFrame。 这是因为iFrame无法找到元素。

下面是代码片段。现在我用什么XPath来定位类= “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"> 

相关问题