在pycharm中获得python selenium中的TypeError错误



->这是我的一个文件booking.py

from selenium import webdriver
import os
class Task(webdriver.Chrome):
def __init__(self,
driver_path=webdriver.Chrome(executable_path=r"/home/mank/Documents/webdriver/chromedriver")):
self.driver_path = driver_path
os.environ['PATH'] += self.driver_path
super(Task, self).__init__()
self.implicitly_wait(10)
self.maximize_window()
self.get('https://www.sample.com/')
  1. run.py的第二个文件
from bot.booking import Task
with Task() as bot:
bot.landing_page()
print("exiting..")

---->尝试运行run.py .请检查并让我知道,谢谢

错误信息:

Traceback (most recent call last):
File "/home/mank/PycharmProjects/botnew/bot/run.py", line 3, in <module>
with Task() as bot:
File "/home/mank/PycharmProjects/botnew/bot/booking.py", line 14, in __init__
os.environ['PATH'] +=self.driver_path
TypeError: can only concatenate str (not "WebDriver") to str

self.driver_path是WebDriver类型,但在您的代码中,它被视为字符串。
所以你的代码在os.environ['PATH'] += self.driver_path行失败-只是删除该行应该修复当前的错误信息。

最新更新