0

我正在尝试使用 CasperJS 向自己发送一条新消息,并且我需要该消息包含一个链接<a href="www.example.com"></a>

这是我的一小段代码

casper.then(function(){
    this.waitForText("To", function(){
        this.sendKeys("div[aria-label='Message body']","<p>This a message.</p> 
                <a href='http://example.com'>example.com</a>\n ");
    });
    this.wait(5000);
});

主要问题是当我使用this.sendKeys()casper 功能将文本发送到正文消息时,它确实将文本发送到您编写消息的框,但我需要 example.com 作为链接到达正文消息,我试过了传递一个<a>html 标签,但它不像我预期的那样工作。

这是我认为解决相同问题的另一个想法。您知道,当您发送消息时,您可以单击“插入超链接”按钮,使用此代码,我进行单击,它会打开一个小窗口,您可以在其中粘贴超链接并按确定。这是代码,一切都很好。

casper.then(function(){
  this.waitForText("To", function(){
  this.click('button[title="Insert hyperlink"]');
  });
  this.wait(5000);
});

casper.then(function(){
  this.waitForText("URL",function(){
    this.sendKeys("input[role='textbox']","http://example.me");
  });
  this.wait(5000);
});
casper.then(function(){
  this.waitForText("OK",function(){
    this.clickLabel("OK");
  });
  this.wait(5000);
});

问题是当单击“确定”按钮时,正文消息内没有出现任何超链接。所以我想我需要先选择文本,然后转换为超链接。

4

0 回答 0