In an effort to learn more about Python, Selenium, Beautifulsoup, and webscraping in general I started working a small personal project that should ultimately be able to open a webpage's home screen, navigate to a search field, and enter and search for a specific account number.
Currently I have been successful in using Selenium to open the sites home page and then navigate to the page that contains the form I need to fill. I have done this by using Chromes developer tools to copy the xpath of the area that I need to click on and then feeding that into Selenium's "find element" and "click" functions.
The trouble I am having is that the xpath for the specific field that I am trying to click in, when fed into my code, spits out teh following error
Traceback (most recent call last):
File "C:/Users/WFrazierIII/PycharmProjects/Selenium Prcatice/Selenium Practice File.py", line 24, in <module>
driver.find_element_by_xpath('/html/body/form/table/tbody/tr[2]/td[2]/input').click()
File "C:\Users\WFrazierIII\PycharmProjects\Selenium Prcatice\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\WFrazierIII\PycharmProjects\Selenium Prcatice\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element
'value': value})['value']
File "C:\Users\WFrazierIII\PycharmProjects\Selenium Prcatice\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\WFrazierIII\PycharmProjects\Selenium Prcatice\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[2]/td[2]/input"}
(Session info: chrome=83.0.4103.97)
Process finished with exit code 1
My question is, should I work on finding the proper xpath for this field or should I attempt to use a different "find_element" for a better chance of making my code work.
If it helps, the field I am trying to click on is the "account" field on this website: https://www.alabamagis.com/Tallapoosa/frameset.cfm?cfid=3986761&cftoken=54089502
Here is my current code so far:
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.expected_conditions import presence_of_element_located
driver = webdriver.Chrome('C:\WebDriver\chromedriver.exe')
driver.get('https://www.alabamagis.com/Tallapoosa/')
driver.find_element_by_xpath('/html/body/center/font[2]/a').click()
time.sleep(6)
driver.find_element_by_xpath('/html/body/font/a[1]').click()
time.sleep(6)
driver.find_element_by_xpath('/html/body/form/table/tbody/tr[2]/td[2]/input').click()
Finally, I'll just add that I know very little of Python or Selenium and almost nothing about HTML (hence the lame starter project) so if you think there are better ways to approach this then I would love the guidance.
Thank!