Home > Blockchain >  Cant click or send keys, selenium webdriver python
Cant click or send keys, selenium webdriver python

Time:06-18

I am trying to access the following website: https://infoms.saude.gov.br/extensions/DEMAS_C19VAC_Distr/DEMAS_C19VAC_Distr.html and apply some filters like click on "tipo de vacina" and select a date. When I click on "Tipo de Vacina" I want to select one of the two options. But I cant click with xpath neither can I send keys to to type in what I want. Can someone help me by finding how I can click on "Tipo de vacina" and right after that select one of the two options and click the green button so that I can click afterwards on the date?

here is what I got so far in code (Python)

%pip install selenium webdriver_manager

import requests
from datetime import datetime
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support.ui import WebDriverWait 

url_dist_vacinas = 
'https://infoms.saude.gov.br/extensions/DEMAS_C19VAC_Distr/DEMAS_C19VAC_Distr.html'
driver = webdriver.Chrome()
driver.get(url_dist_vacinas)
print(driver.title)

driver.find_element(By.XPATH,'//*[@id="filtro-04"]/div/article/div[1]/div/div/qv- 
filterpane/div/div/div/div[2]/span').click()

CodePudding user response:

Try the below lines of code, this might help

driver.get("https://infoms.saude.gov.br/extensions/DEMAS_C19VAC_Distr/DEMAS_C19VAC_Distr.html")

clickReviw = WebDriverWait(driver, 40).until(EC.element_to_be_clickable((By.XPATH, "//*[text()='Tipo de vacina']")))
clickReviw.click()
sleep(4)
driver.find_element_by_xpath("//input[@placeholder='Search in listbox']").send_keys("vacina")

btn1 = driver.find_element_by_xpath("(//div[@class='qv-listbox-text qv-listbox-text-value'])[1]")
btn1.click()

btn2 = driver.find_element_by_xpath("//button[@title='Confirm selection']")
btn2.click()

Imports

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from time import sleep
  • Related