I wrote some code in Pycharm last year, to loop through VAT numbers entered into the Gov website, to make sure they were still valid. It still works fine on the original laptop, but not on my other laptop, even thought the code is exactly the same (the only adjustment was for the location of the spreadsheet). I have given my code down below. When I try to run it on my other laptop, it comes up with the following error.
Traceback (most recent call last):
File "C:\Users\neils\Documents\Pycharm Projects\VATChecker\VATChecker.py", line 30, in <module>
VAT = web.find_element_by_xpath('//*[@id="target"]')
^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'WebDriver' object has no attribute 'find_element_by_xpath'
Process finished with exit code 1
One thing I also notice, is that the import sys and import datetime are both greyed out. I guess that's because it crashed before these imports were used?
I should mention, the version of Chrome is the same for both laptops (version 123), and I have the same chromedriver installed for both. Both laptops are windows 64 bit, in case you're thinking that might be the issue.
Are you able to advise me what the problem is please?
import datetime
import sys
from selenium import webdriver
from openpyxl import workbook, load_workbook
from datetime import date
web = webdriver.Chrome()
wb = load_workbook('C:\\Users\\neils\\Documents\\NSO\\Self Billing agreements\\VATMusiciansCheckerUK.xlsx', data_only=True, read_only=False)
ws = wb.active
x=2
y=1
current_datetime = datetime.datetime.now()
current_datetime.strftime('%x %X')
invalid = ""
while ws.cell(x,1).value !=None:
ws.cell(x,9).value = ""
web.get("https://www.tax.service.gov.uk/check-vat-number/enter-vat-details")
web.implicitly_wait(10)
VatNumber = ws.cell(x,4).value
VAT = web.find_element_by_xpath('//*[@id="target"]')
VAT.send_keys(VatNumber)
VAT.submit()
web.implicitly_wait(4)
registered = web.find_element_by_xpath('/html/body/div[2]')
if (registered.text.find("Invalid")) > 0:
ws.cell(x,9).value = "Invalid VAT number"
invalid = invalid + str(y) + " " + ws.cell(x,1).value + " " + ws.cell(x,2).value + ", "
y=y+1
else:
ws.cell(x,9).value = "Valid VAT number"
ws.cell(x,6).value = current_datetime
x=x+1
if invalid == "":
print("All VAT records are correct")
else:
print("Invalid VAT records are " + invalid)
wb.save('C:\\Users\\neils\\Documents\\NSO\\Self Billing agreements\\VATMusiciansCheckerUK.xlsx')
Use
Instead of
Don't forget to add
For more reference refer to this.