简体   繁体   English

收到消息:没有这样的元素:无法找到元素:{"method":"css selector","selector":"[id="None"]"} Python 使用 selenium 时

[英]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.我目前正在尝试使用 selenium 来帮助我在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.这是我收到的错误消息: [9080:29296:0720/161241.697:ERROR:device_event_log_impl.cc(214)] [16:12:41.697] USB:usb_device_handle_win.cc:1048 无法从节点连接读取描述符:连接到系统的设备不工作。 (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) [9080:29296:0720/161241.716:ERROR:device_event_log_impl.cc(214)] [16:12:41.716] USB:usb_device_handle_win.cc:1048 无法从节点连接读取描述符:连接到系统的设备是不工作。 (0x1F) Traceback (most recent call last): File "e:\Job\ApplicationBot\main.py", line 79, in bot.job_search() (0x1F) Traceback(最近一次调用最后一次):文件“e:\Job\ApplicationBot\main.py”,第 79 行,在 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文件“e:\Job\ApplicationBot\main.py”,第 44 行,在 job_search searchDriver = self.driver.find_element() 文件“C:\Users\lihua\AppData\Roaming\Python\Python39\site-packages\selenium \webdriver\remote\webdriver.py",第 857 行,在 find_element 返回 self.execute(Command.FIND_ELEMENT, { File "C:\Users\lihua\AppData\Roaming\Python\Python39\site-packages\selenium\webdriver\ remote\webdriver.py”,第 435 行,在执行 self.error_handler.check_response(response) 文件“C:\Users\lihua\AppData\Roaming\Python\Python39\site-packages\selenium\webdriver\remote\errorhandler.py ",第 247 行,在 check_response 中引发 exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法找到元素:{“method”:“css selector”,“selector”:” [id="None"]"}(会话信息:chrome=103.0.5060.114)堆栈跟踪:回溯:Ordinal0 [0x005756B3+2184883] Ordinal0 [0x0050E5F1+1762801] Ordinal0 [0x00423DA8+802216] Ordinal0 [0x00156DDB40+90004]DDB40+99004 +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] +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.所以我猜测该函数默认为按 id 搜索,但由于你没有给它一个 id,你会得到id=None错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Selenium Python 选择下拉菜单 - 无法定位元素:{“method”:“css selector”,“selector”:"[id= - Selecting drop-down using Selenium Python - Unable to locate element: {“method”:“css selector”,“selector”:"[id= 无法找到硒中的元素:{“方法”:“ css选择器”,“选择器”:“ [id =” identifierId”]”} - Unable to locate element: {“method”:“css selector”,“selector”:“[id=”identifierId“]”} in selenium selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法找到元素:{“方法”:“css选择器”,“选择器”:“.ui流感~”} - selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".ui flu~"} 无法使用python在硒中使用CSS_SELECTOR定位元素 - Unable to locate the element using CSS_SELECTOR in selenium using python 消息:没有这样的元素:无法找到元素:{“method”:“css selector”,“selector”:“[id=”loginUsername“]”} - Message: no such element: Unable to locate element: {“method”:“css selector”,“selector”:“[id=”loginUsername“]”} NoSuchElementException:消息:没有这样的元素:无法找到元素:{"method":"css selector","selector":"[id="events_table"]"} - NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="events_table"]"} 得到以下消息:没有这样的元素:无法定位元素:{“method”:”xpath”,”selector”:”//span[@id='lblError']/text()”}” - Getting the following Message: no such element: Unable to locate element:{“method”:”xpath”,”selector”:”//span[@id=’lblError’]/text()”}” Python: Selenium 没有这样的元素: 无法定位元素: {“method”:“xpath”,“selector”:“//button[@data-id=1]”} - Python: Selenium no such element: Unable to locate element: {“method”:“xpath”,“selector”:“//button[@data-id=1]”} 消息:没有这样的元素:无法定位元素:{“method”:“css selector”,“selector”:“[name=”uID“]”} - Message: no such element: Unable to locate element: {“method”:“css selector”,“selector”:“[name=”uID“]”} selenium 无法使用方法定位元素:无法通过 id、css_selector、xpath、链接文本找到元素 - selenium Unable to locate element using methods: cannot find elements by id, css_selector, xpath, link text
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM