Olá, estou desenvolvendo uma automação em Python com a biblioteca selenium para acessar o site do Econet e retirar os dados de uma tabela a partir de um código de NCM. De inicio escrevi o código para abrir o navegador, acessar a parte do usuário e de pesquisa para NCM's. Porém ao clicar no campo para inserir o NCM me encontro com o seguinte erro:
Traceback (most recent call last):
File "C:/Users/gusta/PyCharmProjects/WebScraping/tes.py", line 32, in <module>
driver.find_element_by_xpath('/html/body/form/table/tbody/tr[1]/td[2]/input').click() #click no campo para inserir o NCM
File "C:\Users\gusta\PyCharmProjects\WebScraping\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 394, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "C:\Users\gusta\PyCharmProjects\WebScraping\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 976, in find_element
return self.execute(Command.FIND_ELEMENT, {
File "C:\Users\gusta\PyCharmProjects\WebScraping\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\gusta\PyCharmProjects\WebScraping\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/form/table/tbody/tr[1]/td[2]/input"}
(Session info: chrome=85.0.4183.121)
Segue abaixo o código:
import time
from selenium import webdriver
# --- #
# --- # chamando o chrome --- #
chromedriver = "C:/Users/gusta/Downloads/chromedriver"
driver = webdriver.Chrome(chromedriver)
url = 'http://www.econeteditora.com.br/'
driver.get(url)
time.sleep(0)
# --- #
login = "/html/body/div[2]/div[2]/div[1]/div/table/tbody/tr[2]/td[1]/div[1]/table/tbody/tr[2]/td[2]/form/table/tbody/tr[1]/td[2]/input"
senha = "/html/body/div[2]/div[2]/div[1]/div/table/tbody/tr[2]/td[1]/div[1]/table/tbody/tr[2]/td[2]/form/table/tbody/tr[2]/td[2]/input[1]"
# --- # login econet
driver.find_element_by_xpath(login).click()
driver.find_element_by_xpath(login).send_keys("") #usuário
driver.find_element_by_xpath(senha).click()
driver.find_element_by_xpath(senha).send_keys("") #senha
driver.find_element_by_xpath('/html/body/div[2]/div[2]/div[1]/div/table/tbody/tr[2]/td[1]/div[1]/table/tbody/tr[2]/td[2]/form/table/tbody/tr[3]/td/img').click()
time.sleep(2)
# --- # busca ncm
driver.find_element_by_xpath('/html/body/div[2]/div[2]/div[1]/div/table/tbody/tr[2]/td[1]/div[3]/div[1]/ul/li[16]/a').click() #click na barra de opções lado esquerdo (NCM)
time.sleep(2)
driver.find_element_by_xpath('/html/body/form/table/tbody/tr[1]/td[2]/input').click() #click no campo para inserir o NCM
time.sleep(2)
# --- #
#driver.quit()