2

I'm using a script to automate a survey that I have to take every morning for work. When I run it it runs fine and it finishes without an issue. After running in the command prompt I keep getting this traceback error.

Code:

from selenium import webdriver
import time
import warnings


warnings.filterwarnings('ignore')
driver = webdriver.Chrome(executable_path="./drivers/chromedriver.exe")
driver.get('https://quickentry.teamhgs.com/')

EmployeeID = *EEID*
LastName = *LASTNAME*

# Wait for webpage to load and click usa employee button
time.sleep(1)
USAEmployeeButton = driver.find_element_by_xpath('/html/body/section/div/div/div/div/div/div[2]/a[1]')
USAEmployeeButton.click()

# input employee button and last name then click verify
EID = driver.find_element_by_xpath('//*[@id="empId"]')
EID.send_keys(EmployeeID)
last = driver.find_element_by_xpath('//*[@id="empLastName"]')
last.send_keys(LastName)
VerifyEmployeeID = driver.find_element_by_xpath('//*[@id="getemp"]')
VerifyEmployeeID.click()

# wait for the verification to finish and click proceed
time.sleep(10)
ProceedButton = driver.find_element_by_xpath('//*[@id="proceed"]')
ProceedButton.click()

# click no on all of them and then next and submit and Yes
Q1No = driver.find_element_by_xpath('/html/body/section/div/div/div/div/div/div[2]/div[2]/div[2]/div[2]/label/p')
Q1No.click()
Next = driver.find_element_by_xpath('//*[@id="next-question"]')
Next.click()
Q2No = driver.find_element_by_xpath('/html/body/section/div/div/div/div/div/div[2]/div[2]/div[2]/div[2]/label/p')
Q2No.click()
Next.click()
Q3No = driver.find_element_by_xpath('/html/body/section/div/div/div/div/div/div[2]/div[2]/div[2]/div[2]/label/p')
Q3No.click()
Next.click()
Q4No = driver.find_element_by_xpath('/html/body/section/div/div/div/div/div/div[2]/div[2]/div[2]/div[2]/label/p')
Q4No.click()
Submit_Button = driver.find_element_by_xpath('//*[@id="submit"]')
Submit_Button.click()
time.sleep(1)
Yes_Button = driver.find_element_by_xpath('/html/body/div[1]/div/div/div[2]/button[2]')
Yes_Button.click()

# check if it worked
get_confirmation_div_text = driver.find_element_by_css_selector('.admit-msg text-center')
Success_Message = "Based on your answers, you are granted access to the site for today’s shift.  Please complete this questionnaire before arriving on-site for any shift moving forward until further notice. Stay safe."
if get_confirmation_div_text.text == Success_Message:
    print("Test Was Successful")
else:
    print("Test wasn't successful")

# Close page when finished
time.sleep(2)
driver.close()

Error:

C:\Users\USERNAME\PycharmProjects\MorningAutomation\venv\Scripts\python.exe C:/Users/USERNAME/PycharmProjects/MorningAutomation/QuickEntry.py

DevTools listening on ws://127.0.0.1:51345/devtools/browser/85f8fdee-9bc5-42ca-adb3-29fe65733ca5
[26408:26860:1213/081313.939:ERROR:chrome_browser_main_extra_parts_metrics.cc(226)] crbug.com/1216328: Checking Bluetooth availability started. Please report if there is no report that this ends.
[26408:26860:1213/081313.939:ERROR:chrome_browser_main_extra_parts_metrics.cc(229)] crbug.com/1216328: Checking Bluetooth availability ended.
[26408:26860:1213/081313.940:ERROR:chrome_browser_main_extra_parts_metrics.cc(232)] crbug.com/1216328: Checking default browser status started. Please report if there is no report that this ends.
[26408:26388:1213/081313.940:ERROR:device_event_log_impl.cc(214)] [08:13:13.940] USB: usb_device_handle_win.cc:1048 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[26408:26388:1213/081313.942:ERROR:device_event_log_impl.cc(214)] [08:13:13.941] USB: usb_device_handle_win.cc:1048 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[26408:26388:1213/081313.946:ERROR:device_event_log_impl.cc(214)] [08:13:13.945] USB: usb_device_handle_win.cc:1048 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[26408:26860:1213/081313.959:ERROR:chrome_browser_main_extra_parts_metrics.cc(236)] crbug.com/1216328: Checking default browser status ended.
Traceback (most recent call last):
  File "C:\Users\alex.olivas\PycharmProjects\MorningAutomation\QuickEntry.py", line 51, in <module>
    get_confirmation_div_text = driver.find_element_by_css_selector('.admit-msg text-center')
  File "C:\Users\alex.olivas\PycharmProjects\MorningAutomation\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 808, in find_element_by_css_selector
    return self.find_element(by=By.CSS_SELECTOR, value=css_selector)
  File "C:\Users\alex.olivas\PycharmProjects\MorningAutomation\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 1244, in find_element
    return self.execute(Command.FIND_ELEMENT, {
  File "C:\Users\alex.olivas\PycharmProjects\MorningAutomation\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 424, in execute
    self.error_handler.check_response(response)
  File "C:\Users\alex.olivas\PycharmProjects\MorningAutomation\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".admit-msg text-center"}
  (Session info: chrome=96.0.4664.93)
Stacktrace:
Backtrace:
        Ordinal0 [0x003C6903+2517251]
        Ordinal0 [0x0035F8E1+2095329]
        Ordinal0 [0x00262848+1058888]
        Ordinal0 [0x0028D448+1233992]
        Ordinal0 [0x0028D63B+1234491]
        Ordinal0 [0x002B7812+1406994]
        Ordinal0 [0x002A650A+1336586]
        Ordinal0 [0x002B5BBF+1399743]
        Ordinal0 [0x002A639B+1336219]
        Ordinal0 [0x002827A7+1189799]
        Ordinal0 [0x00283609+1193481]
        GetHandleVerifier [0x00555904+1577972]
        GetHandleVerifier [0x00600B97+2279047]
        GetHandleVerifier [0x00456D09+534521]
        GetHandleVerifier [0x00455DB9+530601]
        Ordinal0 [0x00364FF9+2117625]
        Ordinal0 [0x003698A8+2136232]
        Ordinal0 [0x003699E2+2136546]
        Ordinal0 [0x00373541+2176321]
        BaseThreadInitThunk [0x762DFA29+25]
        RtlGetAppContainerNamedObjectPath [0x772E7A9E+286]
        RtlGetAppContainerNamedObjectPath [0x772E7A6E+238]

I kept looking for something similar but none of those resolutions seemed to work for me.

1 Answer 1

1

.admit-msg text-center is not a valid . You need to replace the space character with a dot i.e. .

Effectively, your line of coe will be:

get_confirmation_div_text = driver.find_element_by_css_selector('.admit-msg.text-center')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.