I'm trying to send keys to Wordle based on the elements in the HTML, and have found that whenever there is a duplicate of a letter it won't press the key twice.
For example, if word = 'Trent' it will only type 'Tren', but if the word was 'Burnt' the whole word would get sent.
This is my current code;
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get("https://www.wordleunlimited.com/")
word = "Trent"
letters = []
for letter in word:
button = "//div[text()='%s']" % letter.lower()
elem = driver.find_element(By.XPATH, button)
elem.click()
The only workaround I have found for this is to avoid HTML elements altogether and just use the keyboard library. As shown below. Is there anyway to overcome this issue using elements?
from selenium import webdriver
from keyboard import press
from keyboard import write
driver = webdriver.Chrome()
driver.get("https://www.wordleunlimited.com/")
write(word.lower(), delay = 0.05)
press('enter')
CodePudding user response:
You should look at what div[text()=''] does after you select 1 t it makes another div tag with that value.
"//div[contains(@class,'Game-keyboard-button') and text()='%s']" % letter.lower()
you should be targetting the div with a certain class and text.