简体   繁体   中英

Getting Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="None"]"} Python when using selenium

I'm currently trying to use selenium to help me write a auto-apply bot on linkedin. I'm having trouble selecting the "Jobs" element on the linked in website after logging in. The code looks like this:

from unicodedata import name
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import json
from selenium.webdriver.common.by import By
from time import sleep
from sympy import Id           

class EasyApplyLinkedIn ():


    def __init__(self,data):            
        """param initialization"""
        self.email =data ["email"]
        self.password = data["password"]
        self.keywords = data["keywords"]
        self.location = data["location"] 
        self.driver = webdriver.Chrome(r'ApplicationBot\driver_path\chromedriver.exe')
        

    def loginLinkedIn (self):
        self.driver.get("""https://www.linkedin.com/loginsession_redirect=https%3A%2F%2Fwww%2Elinkedin%2Ecom%2Fcompany%2Flogin&fromSignIn=true&trk=organization_guest_nav-header-signin""")

## Introduce email and password and hit enter 
        login_email =self.driver.find_element(By.NAME,'session_key')
        login_email.clear ()
        # basically use the sendkeys fxn to send our info to the page
        login_email.send_keys(self.email)   

        login_password =self.driver.find_element(By.NAME,'session_password')
        login_password.clear ()
        # basically use the sendkeys fxn to send our info to the page
        login_password.send_keys(self.password)
        login_password.send_keys(Keys.RETURN)

    def job_search (self):
        ## clicking on the job button 
        self.driver.implicitly_wait(5)
        searchDriver = self.driver.find_element() 

The below code is where I'm having trouble specifically.

        jobs_link  =searchDriver(By.LINK_TEXT,'Jobs')
        clicl_jobs_link= searchDriver.click
        sleep (1)
        
    
        job_box = searchDriver(By.XPATH,"//*[@id='global-nav']/div/nav/ul/li[7]/button/div/div/li-icon/svg/path")              
        searchDriver.clear()
        send_keyword = searchDriver.send_keys(self.keywords)
        sleep (1)

        ## specify location
        location_box = searchDriver(By.XPATH,"//input[starts-with(@id,'jobs-search-box-location']")                #find via xml path expression
        searchDriver.clear()
        send_location = searchDriver.send_keys(self.location)
        sleep (1)
        ## hitting enter
        searchDriver.send_keys(Keys.RETURN)

I even input some wait time, I've also tried longer wait times than what's in the code but it still doesn't work

if __name__ =='__main__':
    with open ('E:\Job\ApplicationBot\config.json') as config_files:                         
        data = json.load(config_files)
    
    bot = EasyApplyLinkedIn (data)
    bot.loginLinkedIn()
    sleep (5)
    bot.job_search()

This is the error message I'm getting: [9080:29296:0720/161241.697:ERROR:device_event_log_impl.cc(214)] [16:12:41.697] USB: usb_device_handle_win.cc:1048 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F) [9080:29296:0720/161241.716:ERROR:device_event_log_impl.cc(214)] [16:12:41.716] USB: usb_device_handle_win.cc:1048 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F) Traceback (most recent call last): File "e:\Job\ApplicationBot\main.py", line 79, in bot.job_search()
File "e:\Job\ApplicationBot\main.py", line 44, in job_search searchDriver = self.driver.find_element() File "C:\Users\lihua\AppData\Roaming\Python\Python39\site- packages\selenium\webdriver\remote\webdriver.py", line 857, in find_element return self.execute(Command.FIND_ELEMENT, { File "C:\Users\lihua\AppData\Roaming\Python\Python39\site- packages\selenium\webdriver\remote\webdriver.py", line 435, in execute self.error_handler.check_response(response) File "C:\Users\lihua\AppData\Roaming\Python\Python39\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":"[id="None"]"} (Session info: chrome=103.0.5060.114) Stacktrace: Backtrace: Ordinal0 [0x005756B3+2184883] Ordinal0 [0x0050E5F1+1762801] Ordinal0 [0x00423DA8+802216] Ordinal0 [0x00451B40+990016] Ordinal0 [0x00451DDB +990683] Ordinal0 [0x0047EC32+1174578] Ordinal0 [0x0046CB54+1100628] Ordinal0 [0x0047CF52+1167186] Ordinal0 [0x0046C926+1100070] Ordinal0 [0x00446EA0+945824] Ordinal0 [0x00447D96+949654] GetHandleVerifier [0x00814192+2704034] GetHandleVerifier [0x0080687D+2648461] GetHandleVerifier [0x0060119A+529066] GetHandleVerifier [0x00600006+524566] Ordinal0 [0x00514F2B+1789739] Ordinal0 [0x00519978+1808760] Ordinal0 [0x00519A65+1808997] Ordinal0 [0x00522A01+1845761] BaseThreadInitThunk [0x76CAFA29+25] RtlGetAppContainerNamedObjectPath [0x77A87A9E+286] RtlGetAppContainerNamedObjectPath [0x77A87A6E+238]

I think this line of code is the problem:

searchDriver = self.driver.find_element()

What is the purpose of this code? You're telling it to search, but you haven't told it what to search for .

So I'm guessing the function defaults to searching by id, but since you didn't give it an id, you get the id=None error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM