我正在使用以下代码。
import pytest
import time
import json
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
#login
driver = webdriver.Chrome()
driver.get("url")
#time.sleep(10)
driver.set_window_size(920, 680)
driver.find_element(By.ID, "loginUserName").send_keys("xx")
driver.find_element(By.ID, "loginPassword").send_keys("yy")
driver.find_element(By.ID, "loginButton").click()
对我来说工作正常,并且我不包含chrome-extension的任何路径和设置属性。如果我共享此程序,对方将出现以下错误,并且他们有chromedriver .exe在python文件夹中,并在同一文件夹中创建了这个python文件
回溯(最近通话最近):文件 “ C:\ Users \ 1025043 \ AppData \ Local \ Programs \ Python \ Python37-32 \ anu \ 1.py”, 第8行 driver = webdriver.Chrome(chrome_driver_path)NameError:未定义名称“ chrome_driver_path”
我走的路上,
['', 'C:\ Users \ 1024983 \ AppData \ Local \ Programs \ Python \ Python37 \ python37.zip', 'C:\ Users \ 1024983 \ AppData \ Local \ Programs \ Python \ Python37 \ DLLs', 'C:\ Users \ 1024983 \ AppData \ Local \ Programs \ Python \ Python37 \ lib', 'C:\ Users \ 1024983 \ AppData \ Local \ Programs \ Python \ Python37', 'C:\ Users \ 1024983 \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ site-packages', 'C:\ Users \ 1024983 \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ site-packages \ win32', 'C:\ Users \ 1024983 \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ site-packages \ win32 \ lib', 'C:\ Users \ 1024983 \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ site-packages \ Pythonwin']
这是什么原因?
注意:我正在使用Windows 10,Python 3.7.4,Selenium 3.141.0,Chrome版本78.0.3904.108(相反的人也仅使用此版本)
答案 0 :(得分:0)
chromedriver.exe应该包含在可执行文件PATH中。 下载chromedriver.exe并将其添加到以下代码中。 (添加Chrome驱动程序路径,因为它位于您的计算机中),或者您可以将其包含在Windows 10环境变量中的PATH变量中。
例如
Option Explicit
Public Sub CopyFormattingsAndFormulasOnly()
Dim ws As Worksheet
Set ws = ThisWorkbook.ActiveSheet
Dim Source As Range
Set Source = ws.Range("A1:L5")
Dim Destination As Range
Set Destination = ws.Cells(ws.Rows.Count, "A").End(xlUp).Offset(RowOffset:=1).Resize(Source.Rows.Count, Source.Columns.Count)
Source.Copy
Destination.PasteSpecial xlPasteAll
On Error Resume Next
Destination.SpecialCells(xlCellTypeConstants).ClearContents
On Error Goto 0
End Sub