from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
options = webdriver.ChromeOptions()
options.add_experimental_option("detach", True)
driver = webdriver.Chrome(options = options, service = Service(ChromeDriverManager().install()))
driver.get("https://sanctum.pl/register.html")
driver.maximize_window()
#Lokalizatory
x = "Josh123"
y= "josh123@gmail.com"
input_first_name = driver.find_element_by_xpath("/html/body/div[1]/div[1]/section[2]/div/div/div[2]/div[2]/div/div/div[2]/div/span/form/div[2]/fieldset/div/input").send_keys(x)
input_last_name = driver.find_element_by_xpath("/html/body/div[1]/div[1]/section[2]/div/div/div[2]/div[2]/div/div/div[2]/div/span/form/div[1]/fieldset/div/input").send_keys(y)
我试图把一些数据到浏览表单,但它是不工作的任何建议?我也得到这个在终端
DevTools listening on ws://127.0.0.1:50932/devtools/browser/f9638d1b-c140-4146-9d53-f5534ea6c850
Traceback (most recent call last):
File "e:\Python\Selenium\skrypt.py", line 19, in <module>
input_first_name = driver.find_element_by_xpath("/html/body/div[1]/div[1]/section[2]/div/div/div[2]/div[2]/div/div/div[2]/div/span/form/div[2]/fieldset/div/input").send_keys(x)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'WebDriver' object has no attribute 'find_element_by_xpath'
PS E:\Python\Selenium> [6268:18388:0306/204146.997:ERROR:device_event_log_impl.cc(218)] [20:41:46.997]
USB: usb_device_handle_win.cc:1046 Failed to read descriptor from node connection: Urz╣dzenie do│╣czonennection: Urz╣dzenie do│╣czone do komputera nie dzia│a. (0x1F)
2条答案
按热度按时间swvgeqrz1#
此错误消息...
...意味着您正在使用的 Selenium 客户端版本没有
find_element_by_*
commands are deprecated的 *find_element_by_xpath
* 属性溶液
取代:
您必须用途:
此用例
您的有效代码行将是:
时间;日期
AttributeError: 'WebDriver' object has no attribute 'find_element_by_xpath'
rur96b6h2#
不是Python中Selenium的有效语法。
它应该是:
reference