Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 尝试使用selenium自动注册。遇到问题_Python_Selenium - Fatal编程技术网

Python 尝试使用selenium自动注册。遇到问题

Python 尝试使用selenium自动注册。遇到问题,python,selenium,Python,Selenium,目前正在尝试使用Selenium在“mail.com”上自动注册。到目前为止,我已经设法让程序转到URL。我遇到的问题是,即使我复制了“注册”的完整XPATH,我也会得到一个: “selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:找不到元素:{”方法“:“xpath”,“选择器”:“/html/body/table/tbody/tr[114]/td[2]”}” 错误 以下是我目前正在使用的代码: import seleniu

目前正在尝试使用Selenium在“mail.com”上自动注册。到目前为止,我已经设法让程序转到URL。我遇到的问题是,即使我复制了“注册”的完整XPATH,我也会得到一个:

selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:找不到元素:{”方法“:“xpath”,“选择器”:“/html/body/table/tbody/tr[114]/td[2]”}

错误

以下是我目前正在使用的代码:

import selenium
import time
from selenium.webdriver.common.by import By

driver = selenium.webdriver.Chrome(executable_path='pathtochromedriver')
driver.get('https://www.mail.com/')
driver.maximize_window()

# Delay added to allow elements to load on webpage
time.sleep(30)

# Find the signup element
sign_up = driver.find_element_by_xpath('/html/body/table/tbody/tr[114]/td[2]')

尝试使用ActionsChains滚动以确保元素在视图中

from selenium.webdriver.common.action_chains import ActionChains

some_page_item = driver.find_element_by_class_name('some_class')
ActionsChains(driver).move_to_element(some_page_item).click(some_page_item).perform()
还有一个提示。。。与其简单地使用time.sleep()等待元素出现,不如使用WebDriverWait

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

wait_for_item = WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.CLASS_NAME ,"some_class_name")))


30是项目出现前等待的秒数;但是,如果它在30秒之前出现,则它将立即继续执行。如果30秒过去,项目没有出现,将发生超时错误

按钮“注册”的xpath似乎与您列出的不同。还有,为什么不直接使用id呢?xpath在某些情况下可能更脆弱。按钮的id为signup button尝试:sign_up=driver。通过xpath(“signup-button”)查找元素仍然会遇到相同的错误尝试此xpath=
//a[@id='signup-button']]/span
使用显式waitwell,如果目标是id,则必须使用通过id查找元素。signup=driver。通过id(“signup-button”)查找元素