提问人:Thomas Satirsley 提问时间:5/10/2022 最后编辑:Thomas Satirsley 更新时间:5/10/2022 访问量:86
将 Python Selenium 与 Chromedriver 一起使用,无法以 AI Dungeon 接受的方式将文本添加到文本区域作为输入
Using Python Selenium with Chromedriver, unable to add text to a textarea in a way that AI Dungeon will accept as input
问:
我正在尝试为我正在编写的程序向 AI Dungeon 添加文本,以在 AI Dungeon 之上构建更复杂的系统。
我能够用 Selenium 让它进入这个屏幕:
但是由于某种原因,我尝试将文本放入文本区域的每个方法都没有被 AI Dungeon 接受。
我尝试针对的元素是:
<textarea autocorrect="on" maxlength="4000" placeholder="What happens next?" autocapitalize="sentences" autocomplete="on" dir="auto" rows="1" spellcheck="true" aria-label="What happens next?" class="css-11aywtz r-13awgt0 r-1777fci r-snp9zz" style="background-color: rgb(18, 18, 18); border-radius: 8px; color: rgb(224, 224, 224); font-family: HelveticaNeue-Light, Helvetica, sans-serif, Classic, Alegreya-Regular; font-size: 20px; padding: 12px 8px 8px; vertical-align: top;"></textarea>
我尝试过的例子:
尝试 1
driver.execute_script('document.querySelector(\'[aria-label="What happens next?"]\').value = "Q: What is the meaning of life, the universe and everything?";')
第一个明显地使文本出现在框中,但是当我运行 javascript 脚本以单击 Selenium 时,它不起作用。(我尝试手动在文本区域中输入相同的文本,然后在 Chrome 中手动运行我的 javascript 点击脚本,它确实有效。
具体发生的事情是 AI Dungeon 抛出一个错误,说它无法继续这个故事,因为还不存在。我已经测试过了,如果您尝试在新故事中提交空白文本区域,也会抛出相同的错误。
尝试 2
driver.execute_script('document.querySelector(\'[aria-label="What happens next?"]\').innerHTML = "Q: What is the meaning of life, the universe and everything?";')
文本不会明显地出现在 textarea 中,但 getInnerHTML() 确实返回了我输入的值。
尝试 3
driver.execute_script('document.querySelector(\'[aria-label="What happens next?"]\').innerText = "Q: What is the meaning of life, the universe and everything?";')
文本不会明显地显示在 textarea 中。
我错过了什么吗?AI Dungeon 是否有可能被设置为阻止这些类型的 javascript 被运行?如果是这样,有没有办法绕过它们,以另一种方式做我想做的事?还是我以完全错误的方式去做这件事?
答: 暂无答案
评论