ModuleNotFoundError:没有名为“ selenium.webdriver.common.support”的模块

时间:2020-07-28 07:38:04

标签: python python-3.x selenium

我已经使用pip install selenium安装了硒,并且正在学习。但这发生了:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.common.support.ui import WebDriverWait
from selenium.webdriver.common.support import expected_conditions as EC
import time

PATH = "/Users/mattmac/Downloads/chromedriver"
driver = webdriver.Chrome(PATH)
Traceback (most recent call last): File "<stdin>", line 1, in <module> ModuleNotFoundError: No module named 'selenium.webdriver.common.support'

3 个答案:

答案 0 :(得分:3)

只需测试一下。好像不需要从import random VOWEL_COST = 250 LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' VOWELS = 'AEIOU' class WOFPlayer: def __init__(self, name): self.name = name self.prizeMoney = 0 self.prizes = [] def addMoney(self, amt): self.prizeMoney += amt def goBankrupt(self): self.prizeMoney = 0 def addPrize(self, prize): self.prizes.append(prize) def __str__(self): return '{} (${})'.format(self.name, self.prizeMoney) class WOFHumanPlayer(WOFPlayer): def getMove(self, category, obscuredPhrase, guessed): return input("""{} has ${} Category: {} Phrase: {} Guessed: {} Guess a letter, phrase, or type 'exit' or 'pass':)""". format(self.name, self.prizeMoney, category, obscured_phrase, guessed)) class WOFComputerPlayer(WOFPlayer): def __init__(self, name, difficulty): WOFPlayer.__init__(self, name) self.difficulty = difficulty SORTED_FREQUENCIES = 'ZQXJKVBPYGFWMUCLDRHSNIOATE' def smartCoinFlip(self): flip = random.randint(1, 10) if flip > self.difficulty: return False else: return True def getPossibleLetters(self, guessed): possible_letters = [] for x in LETTERS: if x in VOWELS and self.prizeMoney < VOWEL_COST: continue if x in guessed: continue possible_letters.append(x) return possible_letters def getMove(self, category, obscuredPhrase, guessed): possible_letters = self.getPossibleLetters(guessed) if possible_letters == []: return 'pass' coinflip = self.smartCoinFlip() if coinflip == True: sorted_list = sorted(possible_letters, reverse = True, key = lambda x: WOFComputerPlayer.SORTED_FREQUENCIES.find(x)) return sorted_list[0] else: return sorted_list[ random.randrange(len(sorted_list))] x = WOFComputerPlayer('boy', 5) y = x.getMove('matter', 'co______', 'co') print(y) 导入support。尝试像这样导入:

common

答案 1 :(得分:1)

尝试以下代码:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time


driver = webdriver.Chrome(executable_path="chromedriver.exe")
driver.get("Your URL")

答案 2 :(得分:1)

您要导入WebDriverWait的路径不是selenium.webdriver.common.support.ui,而是 selenium.webdriver.support.ui 。因此,您需要有效地替换以下行:

from selenium.webdriver.common.support.ui import WebDriverWait

具有:

from selenium.webdriver.support.ui import WebDriverWait

类似地,导入expected_conditions的路径不是selenium.webdriver.common.support,而是 selenium.webdriver.support import 。因此,您需要有效地替换以下行:

from selenium.webdriver.common.support import expected_conditions as EC

具有:

from selenium.webdriver.support import expected_conditions as EC