-1
Hello, I’m developing a Python automation with the Selenium library to access the Econet website and retrieve data from a table from an NCM code. At first I wrote the code to open the browser, access the user and search part for NCM’s. But when clicking on the field to enter the NCM I find the following error:
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)
Follow the code below:
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()
Gustavo, good morning! In your original code with 'user' and 'password' you can access the next page?
– lmonferrari
Imonferrari, good morning! I can do it. When he needs to click on line 32, he gives me the error.
– Gustavo Gonçalves