0

I m planning to automate whatsapp replies with selenium so i used webdriver class and created a object. While compiling it shows syntax error. Though i checked it was correct.

I tried importing all class related to webdriver or i would have missed some.

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)

File "bot.py", line 19 WebDriverWait wait = new WebDriverWait(driver,30);

3 Answers 3

3

WebDriverWait wait = new WebDriverWait(driver, 30); is Java syntax, not Python.

Python doesn't use type declaration, doesn't use new for objects and doesn't use ; at line end.

It should be

wait = WebDriverWait(driver, 30)
Sign up to request clarification or add additional context in comments.

Comments

1
WebDriverWait wait = new WebDriverWait(driver,30);

//Error line* Replace this with below line

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30));

Comments

0

You have a colon (";") at the end of the line. No need for that in Python.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.