如何选择复杂的输入字段?

时间:2016-08-13 00:22:20

标签: selenium selenium-webdriver

如何选择实际上是输入textarea的元素? 它显示如下:

<form>
    ...
        <iframe class="redactor_textCtrl redactor_MessageEditor redactor_BbCodeWysiwygEditor redactor_" frameborder="0">

            <html webdriver="true">

            <head>
            <base href="someUrl">
            <link rel="stylesheet" href="someUrl">
            </head>

            <body style="overflow-y: hidden; dir="LTR" contenteditable="true">
                  //the input area is here on the page
            <p><br></p>
            </body>

            </html>

       </iframe>

        <textarea name="message_html" id="ctrl_message_html" class="textCtrl MessageEditor BbCodeWysiwygEditor " ... </textarea>
        ...
</form>

我试图选择textarea元素,但它不起作用。

1 个答案:

答案 0 :(得分:0)

(假设你使用的是Java)实际上你需要在找到文本编辑器元素之前切换iframe,如下所示: -

driver.switchTo().frame(driver.fimdElement(By.cssSelector("iframe.redactor_textCtrl.redactor_MessageEditor.redactor_BbCodeWysiwygEditor redactor_")));

//Now find the text editor 
WebElement texteditor = driver.findElement(By.tagName("body"));

//Now you can send keys here
texteditor.sendKeys("your value");