简体   繁体   English

Python 和 selenium 语法无效

[英]Python and selenium invalid syntax

When I enter this it says invalid syntax at the end.click .当我输入它时,它在end.click处显示invalid syntax and webdriverwait waitwebdriverwait 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 1.你的缩进错误

2.You are missing a space between new and WebDriverWait 2.您在newWebDriverWait之间缺少一个空格

3.You have a semi-colon ; 3.你有一个分号; on the WebDriverWait line when you shouldn't当你不应该在WebDriverWait线上

4.You have have 2 backticks `` at the end of the attack1 line 4.你有2个反引号``attack1行的末尾

5. WebDriverWaitwait should be WebDriverWait wait and you are missing a parenthesis 5. WebDriverWaitwait应该是WebDriverWait wait并且你缺少一个括号

6.If you define the variable wait you need to use it on the actual wait call beneath it, not call WebDriverWait again 6.如果你定义了变量wait ,你需要在它下面的实际wait调用中使用它,而不是再次调用WebDriverWait

7.Your presence_Of_Elements_Located should be presence_of_elements_located if more than one or presence_of_element_located if single element 7.如果有多个元素,您的presence_Of_Elements_Located应该是presence_of_elements_located ,如果是单个元素,则应该是presence_of_element_located

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如果这不能解决问题,我们将需要查看更多您的代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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