我打算用硒自动化whatsapp的回复,所以我使用了webdriver类并创建了一个对象。编译时显示语法错误。虽然我检查了它是正确的。
我尝试导入所有与webdriver相关的类,否则我会错过一些。
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time
target=str(input("Enter the contact name: "))
string = str(input('Enter your message: '))
n = int(input('spam count: '))
browser = webdriver.Firefox()
browser.get("https://web.whatsapp.com/")
print("Scan the QR code with your android mobile from whatsapp")
time.sleep(60)
x_arg = '//span[contains(@title, '+ '"' +target + '"'+ ')]'
print(x_arg)
WebDriverWait wait = new WebDriverWait(driver,30);*//Error line*
person_title = wait.until(EC.presence_of_element_located((By.XPATH, x_arg)))
print(person_title)
person_title.click()
inp_xpath = '//div[@class="_2S1VP copyable-text selectable-text"]'
input_box = wait.until(EC.presence_of_element_located((By.XPATH, inp_xpath)))
for i in range(n):
input_box.send_keys(string + Keys.ENTER)
time.sleep(1)
文件“ bot.py”,第19行 WebDriverWait wait =新的WebDriverWait(driver,30);
答案 0 :(得分:1)
WebDriverWait wait = new WebDriverWait(driver, 30);
是Java语法,而不是Python。
Python不使用类型声明,不对对象使用new
,在行尾也不使用;
。
应该是
wait = WebDriverWait(driver, 30)
答案 1 :(得分:0)
该行的末尾有一个冒号(“;”)。在Python中无需这样做。