如何解决使用Selenium从web.skype.com发送自动文本消息
我正在尝试使用 Selenium 从 Skype 网络客户端发送自动短信。
到目前为止,我已经能够进行身份验证并选择所需的唯一收件人。它可以通过编程方式( Java 绑定)和使用 Selenium IDE 正常运行。 但是我无法成功将文本添加到消息框中。除此之外, Skype 甚至不显示发送按钮!
input_messages = browser.find_element_by_name('messageInput')
input_messages.send_keys('Testing Output' + Keys.RETURN)
但是我想 Microsoft 更改了Web客户端,因为它不再起作用,即除非消息框中没有写东西,否则不显示“发送”按钮:
使用 Selenium IDE ,它记录以下命令集(省略了 Skype 身份验证):
但是,在上述脚本上运行时,我得到的是似乎在原始“键入消息”顶部重叠的“测试”字符串:
在我看来, Selenium IDE 并未将我的“测试”字符串放在“正确”的位置。因此,甚至没有显示发送按钮。
这是“修改内容”参数:
目标
css=.notranslate
xpath=//div[2]/div[2]/div/div/div/div/div/div/div/div[2]/div/div/div/div[2]/div/div/div
值
<div data-contents="true"><div class="" data-block="true" data-editor="f244q" data-offset-key="0-0-0"><div data-offset-key="0-0-0" class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr"><span data-offset-key="0-0-0"><span data-text="true">Test</span></span></div></div></div>
那么,您知道Selenium IDE(或我自己)在做什么错吗?...
什么是正确的定位器以及如何编辑其内容(以设置我的短信),请确保随后显示并单击了发送按钮(尽管此时Keys.ENTER就足够了)。
提前谢谢!
Windows 10 - 1903 (64-bit)
Google Chrome 85.0.4183.102 (Official Build) (64-bit)
Selenium IDE 3.17.0
chromedriver_win32-85.0.4183.87
selenium-server-standalone-3.141.59.jar
解决方法
我遇到了类似的问题,并尝试了许多方法:
- 清除sendkeys之前的元素
- 在for循环中多次发送密钥
我无法确定哪种方法有效,所以我将在您的真实项目中为您提供一个代码段。
// for the div element
boolean bl = false;
for (int i = 0; i < 3; i++) {
element.clear();
element.sendKeys(text);
if (element.getText().equals(text)) {
bl = true;
break;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。