我计划用Selify自动化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=new WebDriverWait(驱动程序,30);
3条答案
按热度按时间pcrecxhr1#
WebDriverWait wait = new WebDriverWait(driver, 30);
是Java语法,不是Python。Python不使用类型声明,不对对象使用
new
,也不在行尾使用;
。应该是
ovfsdjhp2#
您的行尾有一个冒号(“;”)。在Python中不需要这样做。
lzfw57am3#
//错误行*将其替换为下面的行