单击在python selenium中不起作用

单击在python selenium中不起作用,python,selenium,selenium-webdriver,automation,browser-automation,Python,Selenium,Selenium Webdriver,Automation,Browser Automation,我正在尝试创建一个机器人,它将填写一个特定网站的注册表格 网站详情- 代码: 问题 驱动程序。通过css选择器查找元素(HackNNYU.注册按钮)。单击() 主要问题在这方面。手动单击注册按钮时工作正常,但当我运行此程序时,我可以看到它正在单击注册按钮,但之后没有发生任何事情。有人能帮我解释一下为什么这不起作用吗?我正在尝试使用bot注册一个事件。我将非常感谢你能提供的任何帮助 错误 有时我总是收到这个错误 selenium.common.exceptions.WebDriverExcepti

我正在尝试创建一个机器人,它将填写一个特定网站的注册表格

网站详情-

代码:

问题

驱动程序。通过css选择器查找元素(HackNNYU.注册按钮)。单击()

主要问题在这方面。手动单击
注册按钮
时工作正常,但当我运行此程序时,我可以看到它正在单击
注册按钮
,但之后没有发生任何事情。有人能帮我解释一下为什么这不起作用吗?我正在尝试使用bot注册一个事件。我将非常感谢你能提供的任何帮助

错误

有时我总是收到这个错误

selenium.common.exceptions.WebDriverException: Message: Element is not clickable at point (796.4000244140625, 45.399993896484375). Other element would receive the click

这可能是时间问题。您可以使用以确保元素可单击

wait = WebDriverWait(driver, 10)
wait.until(expected_conditions.element_to_be_clickable((By.CSS_SELECTOR, HackNNYU.sign_up_button))).click()

在单击按钮之前,最多需要等待10秒钟才能单击该按钮。

通常在单击之前提供等待或睡眠功能将帮助您正确模拟单击。在某些情况下,使用操作单击也有助于我。在爪哇

 Actions moveAndClick=new Actions(driver);
moveAndClick.moveToElement(driver.findElement(By.cssSelector("HackNNYU.sign_up_button"))).click().build().perform();
还有一种方法是使用javascript执行器

WebElement element = driver.findElement(By.cssSelector("HackNNYU.sign_up_button"));
    JavascriptExecutor executor = (JavascriptExecutor)driver;
    executor.executeScript("arguments[0].click();", element);
谢谢,,
Murali

页面顶部有一个横幅,使自动滚动隐藏提交按钮。为了解决这个问题,您可以将滚动行为定义为在底部滚动。此外,您的脚本似乎没有正确单击应显示术语弹出窗口的复选框

以下是在hacknyu上创建新帐户的工作脚本:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# set the scrolling behavior to down
DesiredCapabilities.FIREFOX["elementScrollBehavior"] = 1

driver = webdriver.Firefox()
wait = WebDriverWait(driver, 10)

# load the page
driver.get("http://hacknyu.org/signup")

# get the form element
form = driver.find_element_by_css_selector("form[name='signupForm']")

# fill the fields
form.find_element_by_css_selector("input[name='firstName']").send_keys("myfirstname")
form.find_element_by_css_selector("input[name='lastName']").send_keys("mylastname")
form.find_element_by_css_selector("input[name='email']").send_keys("na@na.na")
form.find_element_by_css_selector("input[name='password']").send_keys("mypassword")

# click and accept terms
form.find_element_by_xpath("//input[@name='terms']/..").click()
wait.until(EC.presence_of_element_located((By.XPATH, "//button[.='Accept']"))).click()
wait.until_not(EC.presence_of_element_located((By.CSS_SELECTOR, ".modal")))

# click on submit
form.find_element_by_css_selector("button[type='submit']").click()

非常感谢你!你能告诉我为什么你的accept\u复选框工作正常,但我的不行吗?您使用的是
xpath
,而我使用的是
css\u选择器
?我不知道为什么,但有时复选框不接受事件,因此我单击了复选框的标签。对于XPath中的点,它意味着值。您能解释更多关于DesiredCapabilities的信息吗?何时使用?功能是驱动程序的设置:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# set the scrolling behavior to down
DesiredCapabilities.FIREFOX["elementScrollBehavior"] = 1

driver = webdriver.Firefox()
wait = WebDriverWait(driver, 10)

# load the page
driver.get("http://hacknyu.org/signup")

# get the form element
form = driver.find_element_by_css_selector("form[name='signupForm']")

# fill the fields
form.find_element_by_css_selector("input[name='firstName']").send_keys("myfirstname")
form.find_element_by_css_selector("input[name='lastName']").send_keys("mylastname")
form.find_element_by_css_selector("input[name='email']").send_keys("na@na.na")
form.find_element_by_css_selector("input[name='password']").send_keys("mypassword")

# click and accept terms
form.find_element_by_xpath("//input[@name='terms']/..").click()
wait.until(EC.presence_of_element_located((By.XPATH, "//button[.='Accept']"))).click()
wait.until_not(EC.presence_of_element_located((By.CSS_SELECTOR, ".modal")))

# click on submit
form.find_element_by_css_selector("button[type='submit']").click()