I was trying to fill sudoku with selenium, but every time raise an element not interactable
Relevant code:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://sudokutable.com/')
driver.find_element_by_xpath('//*[@id="body_wrapper"]/main/section[2]/div[1]/div[2]/div[1]').send_keys('1')
I trying this too, but same result:
sleep(1)
num = driver.find_element_by_xpath('//*[@id="body_wrapper"]/main/section[2]/div[1]/div[2]/div[1]')
num.click()
num.send_keys('1')
If someone know any method to send keys, Im very grateful
CodePudding user response:
First we need to close the Cookie pop-up.
Then we need to find the empty cells and try to fill the cell. The empty cell can be recognized by the class
attribute in the svg
tag.
DOM when the cell is already filled
<div class="game-grid__cell" data-group="1" data-row="0" data-column="4">
<svg class="default" viewBox="0 0 72 72">
DOM when the cell is empty
<div class="game-grid__cell" data-group="0" data-row="0" data-column="1">
<svg class="" viewBox="0 0 72 72">
# Imports required:
from selenium.webdriver import ActionChains
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
driver.get("https://sudokutable.com/")
actions =ActionChains(driver)
wait = WebDriverWait(driver,30)
# Close Cookie pop-up
wait.until(EC.element_to_be_clickable((By.ID,"agree_cookies"))).click()
# Find empty cells and use indexing to fill them up
cell = driver.find_elements_by_xpath("//div[@class='game-grid__group'][1]/div/*[name()='svg' and @class='']")
actions.move_to_element(cell[0]).click().send_keys("1").perform()
CodePudding user response:
Try this instead of num.click()
:
driver.execute_script("arguments[0].click();", num)
To send the keys use:
driver.find_element_by_tag_name('body').send_keys('1')