我正在尝试编写一个与Web应用程序交互的程序。
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
browser = webdriver.Firefox()
browser.get('https://www.easports.com/fifa/ultimate-team/web-app/')
element = WebDriverWait(browser, 20).until(EC.presence_of_element_located(\
(By.ID, 'Login')))
element.click()
print("Found %s" % element)
print("locatione %s" % element.location)
通过设计它应该打开浏览器,等待页面加载,然后找到并单击“登录”按钮。找到“登录”按钮,但它没有点击它。位置显然也是打印错误的坐标。这个问题的可能原因和解决方案是什么?
尝试使用其他逻辑定位按钮。例如,通过类:
element = browser.find_element_by_class_name('call-to-action')
element.click()
要find
并单击Login
按钮,您可以使用以下代码行:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='standard call-to-action']"))).click()