Answer the question
In order to leave comments, you need to log in
Python Selenium how to make click on form button?
Good
afternoon Need help from professionals
I can't click on a button in a form.
Also, it is not possible to set data in the form or click on the checkbox on the form (VIM).
It seems to me that the form is generated through a JS script, which is probably why everything is not so simple.
My code
import os
from selenium import webdriver
from time import sleep
URL = 'https://avtokod.mos.ru/Autohistory#!/Home'
draver = webdriver.Chrome(executable_path=os.path.abspath('chromedriver'))
draver.get(URL)
draver.find_element_by_class_name('npClose').click()
sleep(2)
draver.find_element_by_xpath("//button-ui[@class='hydrated']").click()
Answer the question
In order to leave comments, you need to log in
It seems to me that the form is generated through a JS script, which is probably why everything is not so simple
driver.execute_script
, which will select the necessary elements through JS selectors. import os
from selenium import webdriver
from time import sleep
URL = 'https://avtokod.mos.ru/Autohistory#!/Home'
driver = webdriver.Chrome(executable_path=os.path.abspath('chromedriver'))
driver.get(URL)
sleep(3)
# Переключение на VIN
driver.execute_script("return document.querySelector('autohistory-card').shadowRoot.querySelector('label[for=autoVin]')").click()
# Поле ввода VIN
vin_input = driver.execute_script("return document.querySelector('autohistory-card').shadowRoot.querySelector('input#carVin')")
vin_input.send_keys('1234567890')
# Поле ввода СТС
sts_input = driver.execute_script("return document.querySelector('autohistory-card').shadowRoot.querySelector('input#carSts')")
sts_input.send_keys('1234567890')
# Кнопка проверить. Она лежит в еще одном shadow-root
driver.execute_script("document.querySelector('autohistory-card').shadowRoot.querySelector('button-ui').shadowRoot.querySelector('button').click()")
sleep(10)
driver.quit()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question