0

I'm trying to add text to AI Dungeon for a program that I am writing to build more complex systems on top of AI Dungeon.

I'm able to get it to this screen with Selenium:

enter image description here

But every method I've tried to put text in the textarea doesn't get accepted by AI Dungeon for some reason.

The element I'm trying to target is:

<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>

Examples of what I've tried:

Attempt 1

driver.execute_script('document.querySelector(\'[aria-label="What happens next?"]\').value = "Q: What is the meaning of life, the universe and everything?";')

enter image description here

enter image description here

This first one visibly makes the text appear in the box, but when I run the javascript script to click in Selenium it doesn't works. (I've tried manually typing the same text into the textarea, and then manually running my javascript click script in Chrome, and it does work.)

The specific thing that happens is that AI Dungeon throws an error saying it couldn't continue the story because one doesn't exist yet. I've tested it out, and the same error gets thrown if you try to submit a blank textarea in a new story.

enter image description here

Attempt 2

driver.execute_script('document.querySelector(\'[aria-label="What happens next?"]\').innerHTML = "Q: What is the meaning of life, the universe and everything?";')

Text doesn't visibly appear in textarea, but getInnerHTML() does return the value I entered.

Attempt 3

driver.execute_script('document.querySelector(\'[aria-label="What happens next?"]\').innerText = "Q: What is the meaning of life, the universe and everything?";')

Text doesn't visibly appear in textarea.

Is there something I'm missing? Is it possible that AI Dungeon is set up to stop these kinds of javascripts from being run? If so, would there be any way to bypass them and do what I want another way? Or am I going about this in the completely wrong way?

2
  • I think the onchange event doesn't fire when you do it that way, what about doing it with sendkeys? Commented May 10, 2022 at 1:51
  • I should have mentioned. I tried sendkeys to start, but the textarea is considered "non-interactable" by Selenium. That's the reason I've been trying to do it with javascript instead. Commented May 10, 2022 at 4:56

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.