简体   繁体   中英

Python and selenium invalid syntax

When I enter this it says invalid syntax at the end.click . and webdriverwait wait

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 
import random as r
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

driver = webdriver.Chrome()
nt = "Enter Name: "
np = "Enter Password: "
driver.maximize_window()

driver.get("https://www.delugerpg.com/login")
time.sleep(1)
login = driver.find_element_by_name("username")
login.send_keys(nt)
login = driver.find_element_by_name("password")
login.send_keys(np)
login.send_keys(Keys.RETURN)
time.sleep(1)

driver.get("https://www.delugerpg.com/battle/gym/108")
found = True
while found == True:
        link = driver.find_element_by_class_name("btn-battle-action")
        link.click()
        print("Starting Battle")
        time.sleep(1)
        attack1 = driver.find_element_by_class_name("btn-battle-action")
        attack1.click()
        print("Take this")
        time.sleep(1)
        link1 = driver.find_element_by_class_name("btn-battle-action")
        link1.click
        WebDriverWait wait = new WebDriverWait(driver,1)
        end = wait.until(EC.presence_of_elements_located(("Class","btn.battle-default"))
        end.click()


1.Your indentation is wrong

2.You are missing a space between new and WebDriverWait

3.You have a semi-colon ; on the WebDriverWait line when you shouldn't

4.You have have 2 backticks `` at the end of the attack1 line

5. WebDriverWaitwait should be WebDriverWait wait and you are missing a parenthesis

6.If you define the variable wait you need to use it on the actual wait call beneath it, not call WebDriverWait again

7.Your presence_Of_Elements_Located should be presence_of_elements_located if more than one or presence_of_element_located if single element

while found == True:
        link = driver.find_element_by_class_name("btn-battle-action")
        link.click()
        print("Starting Battle")
        time.sleep(1)
        attack1 = driver.find_element_by_class_name("btn-battle-action")
        attack1.click()
        print("Take this")
        time.sleep(1)
        link1 = driver.find_element_by_class_name("btn-battle-action")
        link1.click()
        WebDriverWait wait = new WebDriverWait(driver,1)
        end = wait.until(EC.presence_of_elements_located(("Class","btn.battle-default")))
        end.click()

If that doesn't solve it we will need to see more of your code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM