I am trying to make a script using python that checks attendance checkboxes according to the names recorded in an excel sheet, so I'm using both selenium and pandas. I wrote a similar script in the past using geckodriver (because I use Firefox mainly), this time however I'm required to use chromedriver. The thing is using Chrome, the script goes to great lengths so that it will never work as intended, here are some of the errors I get just by executing the script.
[file]
[file]:8: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
driver = webdriver.Chrome(executable_path=driver_path,options=options)
DevTools listening on ws://127.0.0.1:53053/devtools/browser/28e3a28f-d7df-4a34-8f22-ed4aeffebca6
id: [10224:9828:0522/111925.401:ERROR:device_event_log_impl.cc(214)] [11:19:25.401] Bluetooth: bluetooth_adapter_winrt.cc:1075
Getting Default Adapter failed.
[user input]
password: [user input]
[file]:12: DeprecationWarning: find_element_by_* commands are deprecated. Please use find_element() instead
driver.find_element_by_id('loginid').send_keys(loginid)
[file]:13: DeprecationWarning: find_element_by_* commands are deprecated. Please use find_element() instead
driver.find_element_by_id('loginpass').send_keys(loginpass)
Enter the name of the sheet: [user input]
Which week is it? [user input]
[file]:22: DeprecationWarning: find_element_by_class_name is deprecated. Please use find_element(by=By.CLASS_NAME, value=name) instead
if df.iloc[i]['name']==driver.find_element_by_class_name('name').get_attribute('value'):
PS [path]> [10224:12100:0522/112023.321:ERROR:util.cc(126)] Can't create base directory: C:\Program Files\Google\GoogleUpdater
When I copied the syntax from the warnings they don't get recognized and throw more errors, also logging in with that script doesn't go smoothly, I have to login twice because every time the first login throws a 400 and 404 errors from the database side at the same time.
Pandas works fine, when I ask it to print the info it reads things properly, the problem is in Selenium mainly. Here's the script code:
import pandas as pd
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
driver_path = './chromedriver'
url = [URL]
options = Options()
driver = webdriver.Chrome(executable_path=driver_path,options=options)
loginid=input("id: ")
loginpass=input("password: ")
driver.get(url)
driver.find_element_by_id('loginid').send_keys(loginid)
driver.find_element_by_id('loginpass').send_keys(loginpass)
sheet=input("Enter the name of the sheet: ")
if sheet.endswith('.xls'):
df = pd.read_excel(sheet)
else:
df = pd.read_csv(sheet)
w=input("Which week is it? ")
week='w'+w
for i in range(len(df)):
if df.iloc[i]['name']==driver.find_element_by_class_name('name').get_attribute('value'):
driver.find_element_by_class_name(week).click()
print(driver.find_element_by_class_name('name').get_attribute('value'))
break
Update: the code is modernized but now there's the same for loop issue persists, it used to do nothing and just closes but when I ran the script on debug mode, it keeps saying the variable result i is a float even though when I print it says the type is string which is what it should be. I tried str() but this makes it come out as NaN. That's the loop I rewrote which gives the same result.
for i in range(len(df)):
name=df.iloc[i]['name']
print(type(name))
# find the p containing the name
p=driver.find_element_by_xpath("//p[contains(@class, 'name') and contains(text(), '"+str(name)+"')]")
print(p)