1

我正在尝试从网页发表评论。评论网页具有文本区域和按钮类型输入

这是textarea的html

<textarea class="aui-field-input aui-field-input-text" id="_33_wgdr_postReplyBody0" name="_33_postReplyBody0" wrap="soft" style="height: 100px; width: 500px;"></textarea>

这是我将一些文本写入 textarea 的方式

HtmlTextArea hta = (HtmlTextArea) commentPage.getElementsByName("_33_postReplyBody0").get(0);
hta.setAttribute("value", "This Is Generated Text");

html页面中的按钮输入是

  <input class="aui-button-input" onclick="wgdr_postReply(0);" type="button" value="Reply" id="_33_wgdr_postReplyButton0"/>

我试图以这种方式单击按钮

 HtmlButtonInput hbi = (HtmlButtonInput) commentPage.getByXPath("//*[@value='Reply' and @type='button']").get(0);
    HtmlPage test = hbi.click();

或者这样

  HtmlButtonInput hbi = (HtmlButtonInput) commentPage.getByXPath("//*[@value='Reply' and @type='button']").get(0);
  String functName = hbi.getAttribute("onclick");
  ScriptResult scriptResult = commentPage.executeJavaScript(functName);

因此,我的网页和数据库应该有一个新的评论“这是生成的文本”,但事实并非如此......我已经通过以下方式初始化了我的网络客户端:

WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_8);
webClient.setJavaScriptEnabled(true);
    webClient.setThrowExceptionOnScriptError(false);
    webClient.setThrowExceptionOnFailingStatusCode(false);
    webClient.setPrintContentOnFailingStatusCode(false);
    webClient.setTimeout(60000);
    webClient.setJavaScriptTimeout(60000);
    webClient.waitForBackgroundJavaScript(10000);

两天以来我一直在研究这个问题,但没有取得丰硕的成果......请发表你的想法谢谢,-Asrar

4

0 回答 0