简体   繁体   English

为什么我会收到此错误:AttributeError: 'Fetch_Info' object has no attribute 'driver' 当我运行我的 selenium_web.py 脚本时

[英]Why do I get this error :AttributeError: 'Fetch_Info' object has no attribute 'driver' when I run my selenium_web.py script

I want to launch the web browser from my script file but when I run my code it gives me an error as 'AttributeError: 'Infow' object has no attribute 'driver'.我想从我的脚本文件中启动 web 浏览器,但是当我运行我的代码时,它给了我一个错误,因为“AttributeError:‘Infow’object 没有属性‘驱动程序’。

I tried finding a solution to this by uninstalling the current version of selenium 4.4.0 and reinstalling a previous version by running the command pip install selenium==4.0.0.b4 but this did not solve my problem.我尝试通过卸载当前版本的 selenium 4.4.0 并通过运行命令pip install selenium==4.0.0.b4重新安装以前的版本来找到解决方案,但这并没有解决我的问题。 My code is supposed to open the web browser when I run it but it is not.我的代码应该在我运行它时打开 web 浏览器,但事实并非如此。 How do I fix this?我该如何解决?

My code:我的代码:

import time
from selenium import webdriver
from selenium.webdriver import chrome
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.keys import Keys


 class Fetch_Info:
def __int__(self):
    self.driver = webdriver.Chrome(
        executable_path="C:\\Users\Whizzy.Ellah\\PycharmProjects\\Voice_Recognition_Virtual_Assistan\\chromedriver.exe")

def get_info(self, query):
    self.query = query
    self.driver.get(url='https://www.wikipedia.org')
    search = self.driver.find_element_by_xpath('//*[@id="searchInput"]')
    search.click()
    search.send_keys(query)
    enter = self.driver.find_element_by_xpath('//*[@id="search-form"]/fieldset/button')
    enter.click()


assist = Fetch_Info()
assist.get_info("hello")

The error:错误:

  File "C:\Users\Whizzy.Ellah\PycharmProjects\Voice_Recognition_Virtual_Assistant\selenium_web.py", line 19, in <module>
assist.get_info("hello") 


"C:\Users\Whizzy.Ellah\PycharmProjects\Voice_Recognition_Virtual_Assistant\selenium_web.py", 
 line 15, in get_info
self.driver.get(url='https://www.wikipedia.org')
 AttributeError: 'Fetch_Info' object has no attribute 'driver'

@Rukamakama below is the error I'm having after making the correction下面的@Rukamakama 是我在更正后遇到的错误

 C:\Users\Whizzy.Ellah\PycharmProjects\Voice_Recognition_Virtual_Assist 
 ant\selenium_web.py:10: DeprecationWarning: executable_path has been 
    deprecated, please pass in a Service object
   self.driver = webdriver.Chrome(
  Traceback (most recent call last):
 File 
     
    "C:\Users\Whizzy.Ellah\Desktop\virtual_assistant_env\lib\site- 
     packages\selenium\webdriver\common\service.py", line 74, in 
      start
   self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Program 


Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
     File "C:\Program 
Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 1420, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file 
specified

  During handling of the above exception, another exception 
  occurred:

 Traceback (most recent call last):

    File `"C:\Users\Whizzy.Ellah\PycharmProjects\Voice_Recognition_Virtual_Assistant\selenium_web.py", line 23, in <module>
assist = Fetch_Info()`


File"C:\Users\Whizzy.Ellah\PycharmProjects\Voice_Recognition_Virtual_Assistant\selenium_web.py", line 10, in __init__
self.driver = webdriver.Chrome(



File "C:\Users\Whizzy.Ellah\Desktop\virtual_assistant_env\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__
super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",

File "C:\Users\Whizzy.Ellah\Desktop\virtual_assistant_env\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 90, in init self.service.start()文件“C:\Users\Whizzy.Ellah\Desktop\virtual_assistant_env\lib\site-packages\selenium\webdriver\chromium\webdriver.py”,第 90 行,在init self.service.start()

File "C:\Users\Whizzy.Ellah\Desktop\virtual_assistant_env\lib\site-packages\selenium\webdriver\common\service.py", line 84, in start raise WebDriverException( selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home文件“C:\Users\Whizzy.Ellah\Desktop\virtual_assistant_env\lib\site-packages\selenium\webdriver\common\service.py”,第 84 行,开始引发 WebDriverException(selenium.common.exceptions.WebDriverException:消息: 'chromedriver.exe' 可执行文件需要在 PATH 中。请参阅https://chromedriver.chromium.org/home

The __init__() function is missing a i . __init__() function 缺少i Please update your code from:请从以下位置更新您的代码:

def __int__(self)

to:至:

def __init__(self)

暂无
暂无

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

相关问题 为什么我会收到错误AttributeError:'module'对象在我的SMS应用程序中没有与Twilio接口的属性'Response'? - Why do I get the error AttributeError: 'module' object has no attribute 'Response' in my SMS app that interfaces with Twilio? 当我在终端上运行django项目时,出现AttributeError:&#39;str&#39;对象没有属性&#39;regex&#39; - when i run my django project on terminal i get the AttributeError: 'str' object has no attribute 'regex' 为什么会出现 AttributeError: 'NoneType' object has no attribute 'something'? - Why do I get AttributeError: 'NoneType' object has no attribute 'something'? 从线程子类的析构函数调用super的析构函数时,为什么会出现“ AttributeError:&#39;super&#39;对象没有属性&#39;__del__&#39;的问题? - Why do I get “AttributeError: 'super' object has no attribute '__del__'” when calling the destructor of super from my Thread subclass' destructor? 为什么我得到 AttributeError: 'NoneType' object has no attribute 'email' - Why do I get AttributeError: 'NoneType' object has no attribute 'email' 为什么会出现 AttributeError: 'NoneType' object has no attribute 'attrs'? - Why do I get AttributeError: 'NoneType' object has no attribute 'attrs'? 为什么在尝试删除目标窗口小部件时出现此错误AttributeError:&#39;NoneType&#39;对象没有属性&#39;remove_widget&#39;? - Why do i get this error AttributeError: 'NoneType' object has no attribute 'remove_widget' when im trying to remove Target widget? Python-Selenium Web驱动程序错误-self._driver.execute-AttributeError:“ unicode”对象没有属性“ id” - Python - Selenium Web Driver error - self._driver.execute - AttributeError: 'unicode' object has no attribute 'id' 为什么会出现此错误? AttributeError: 'list' object 没有属性 'get_cards' - Why do I get this error? AttributeError: 'list' object has no attribute 'get_cards' 为什么我会收到此错误 AttributeError: 'SQLAlchemy' object has no attribute 'models' - why do i get this error AttributeError: 'SQLAlchemy' object has no attribute 'models'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM