gpt4 book ai didi

node.js - 如何在selenium nodejs中无论光标在哪里发送Keys

转载 作者:太空宇宙 更新时间:2023-11-04 01:39:30 24 4
gpt4 key购买 nike

我创建了一个脚本来在 Facebook 帖子中发表评论,我确实点击了评论框,光标确实出现,但无法执行 .sendKeys()

这是我的代码:

var commentBox = driver.findElement(By.xpath('//*[@id="addComment_'+this.postIdSlice+'"]/div/div[2]/div/div/div/div[1]/div'));
actions.mouseMove(commentBox).click().perform();
driver.sleep(2000);
actions.sendKeys("Hello").perform();

但是当我执行时它不会将“Hello”发送到评论框。PS:postIdSlice 是帖子的 id,没有问题,只想在评论框中推送/发送字符串。

最佳答案

使用 Xpath 单击注释框,然后可以使用 ActionSequence 来排序输入和 ENTER 键。

let action = new webdriver.ActionSequence(driver);
action.sendKeys("comment");
action.sendKeys(Keys.ENTER);

action.perform()

关于node.js - 如何在selenium nodejs中无论光标在哪里发送Keys,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53380884/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com