I’m trying to set up some batch look-ups using the orthographic dictionary here. Normally this requires one to type in the search box on the left and then click the “пошук” button beneath it:
There are three elements that seem relevant to me.
search_bar = driver.find_element(By.ID, "ContentPlaceHolder1_tsearch")
search_button = driver.find_element(By.ID, "ContentPlaceHolder1_search")
current_word = driver.find_element(By.CLASS_NAME, "word_style")
The first is the search bar input element; the second is the search (пошук) button below it; and the third corresponds to the element that contains the searched word in the populated result on the right side of the page:
I tried simulating a key-press per the answer here, but the following code did not seem to change the result from “привіт” (the default value) to the searched word “людина”. If anyone is able to see what I’ve messed up, I’d appreciate the help:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
url = "https://lcorp.ulif.org.ua/dictua/"
op = webdriver.ChromeOptions()
op.add_argument('headless')
driver = webdriver.Chrome(options=op)
driver.get(url)
search_bar = driver.find_element(By.ID, "ContentPlaceHolder1_tsearch")
search_button = driver.find_element(By.ID, "ContentPlaceHolder1_search")
search_bar.clear()
search_bar.send_keys("людина")
ActionChains(driver).move_to_element(search_button).click(search_button).key_down(Keys.CONTROL).key_up(Keys.CONTROL).perform()
current_word = driver.find_element(By.CLASS_NAME, "word_style")
print(current_word.text) # привіт, not людина