'while running Selenium getting broken UI in webpage python

having trouble with selenium. Trying to parse one webpage and while running it Im having broken UI, therefore couldn't fill fields with text(getting error not interactable) enter image description here

how it looks in general what i have after running selenium

enter image description here

Message: element not interactable (Session info: chrome=99.0.4844.84) Stacktrace: Backtrace: Ordinal0 [0x00BF9943+2595139] Ordinal0 [0x00B8C9F1+2148849] Ordinal0 [0x00A843F0+1065968] Ordinal0 [0x00AAC4D3+1230035] Ordinal0 [0x00AABB8B+1227659] Ordinal0 [0x00ACB9EC+1358316] Ordinal0 [0x00AA7474+1209460] Ordinal0 [0x00ACBC04+1358852] Ordinal0 [0x00ADBAF2+1424114] Ordinal0 [0x00ACB806+1357830] Ordinal0 [0x00AA6086+1204358] Ordinal0 [0x00AA6F96+1208214] GetHandleVerifier [0x00D9B232+1658114] GetHandleVerifier [0x00E5312C+2411516] GetHandleVerifier [0x00C8F261+560433] GetHandleVerifier [0x00C8E366+556598] Ordinal0 [0x00B9286B+2173035] Ordinal0 [0x00B975F8+2192888] Ordinal0 [0x00B976E5+2193125] Ordinal0 [0x00BA11FC+2232828] BaseThreadInitThunk [0x773EFA29+25] RtlGetAppContainerNamedObjectPath [0x77AA7A7E+286] RtlGetAppContainerNamedObjectPath [0x77AA7A4E+238]

my code:

url = "https://opi.dfo.kz/p/ru/archive-publication/corporative-events-2020-14-07"
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.get(url)
element = driver.find_element(By.XPATH, '//*[@id="CorporativeEvents20201407"]/div[1]/div[1]/div/div[2]/div[1]/span[3]')
element.send_keys('010140000143')

Please help me!



Solution 1:[1]

You can not send text directly to that element.
You should click on that element, this will open another input element where you will be able to insert your text input.
Also you have to use Expected Conditions explicit waits here.
This works:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
url = "https://opi.dfo.kz/p/ru/archive-publication/corporative-events-2020-14-07"
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
wait = WebDriverWait(driver, 20)
wait.until(EC.visibility_of_element_located((By.XPATH, '//*[@id="CorporativeEvents20201407"]/div[1]/div[1]/div/div[2]/div[1]/span[3]'))).click()
wait.until(EC.visibility_of_element_located((By.XPATH, "//input[@class='editor-text tip']"))).send_keys("010140000143")

The '//*[@id="CorporativeEvents20201407"]/div[1]/div[1]/div/div[2]/div[1]/span[3]' XPath locator can and should be improved as well. You can use //div[@class='logic-group-condition' and .//span[@field-name='tbOpiActiveRevisions_flBin']] Instead. This locator is much more reliable. So your code will be:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
url = "https://opi.dfo.kz/p/ru/archive-publication/corporative-events-2020-14-07"
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
wait = WebDriverWait(driver, 20)
wait.until(EC.visibility_of_element_located((By.XPATH, "//div[@class='logic-group-condition' and .//span[@field-name='tbOpiActiveRevisions_flBin']]"))).click()
wait.until(EC.visibility_of_element_located((By.XPATH, "//input[@class='editor-text tip']"))).send_keys("010140000143")

This is the screen shot of the web page after applying my code: enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1