Send_keys Selenium Python là gì?

Chỉ có 2 hành động có thể được thực hiện bằng bàn phím. nhấn xuống một phím và nhả một phím đã nhấn. Ngoài việc hỗ trợ các ký tự ASCII, mỗi phím trên bàn phím đều có một biểu tượng có thể được nhấn hoặc nhả theo trình tự được chỉ định

Ngoài các phím được biểu thị bằng unicode thông thường, các giá trị unicode đã được gán cho các phím bàn phím khác để sử dụng với Selenium. Mỗi ngôn ngữ có cách riêng để tham chiếu các khóa này;

Sử dụng [Phím Java enum][https. //github. com/SeleniumHQ/selenium/blob/selenium-4. 2. 0/java/src/org/openqa/selenium/Keys. java#L28]

Sử dụng [Lớp Python Keys][https. //github. com/SeleniumHQ/selenium/blob/selenium-4. 2. 0/py/selenium/webdriver/common/keys. py#L23]

Sử dụng [. NET tĩnh][https. //github. com/SeleniumHQ/selenium/blob/selenium-4. 2. 0/dotnet/src/webdriver/Keys. cs#L28]

Sử dụng [Hằng số Ruby KEYS][https. //github. com/SeleniumHQ/selenium/blob/selenium-4. 2. 0/rb/lib/selenium/webdriver/common/keys. rb#L28]

Sử dụng [hằng số KHÓA JavaScript][https. //github. com/SeleniumHQ/selenium/blob/selenium-4. 2. 0/javascript/nút/selenium-webdo/lib/đầu vào. js#L44]

Sử dụng [Phím Java enum][https. //github. com/SeleniumHQ/selenium/blob/selenium-4. 2. 0/java/src/org/openqa/selenium/Keys. java#L28]

Đây là một phương pháp tiện lợi trong API hành động kết hợp các lệnh keyDown và keyUp trong một hành động. Việc thực thi lệnh này hơi khác so với việc sử dụng phương thức phần tử, nhưng về cơ bản, lệnh này được sử dụng khi cần nhập nhiều ký tự ở giữa các hành động khác

Đây là một ví dụ về việc sử dụng tất cả các phương pháp trên để thực hiện hành động sao chép/dán. Lưu ý rằng khóa được sử dụng cho thao tác này sẽ khác nhau tùy thuộc vào việc đó có phải là Mac OS hay không. Mã này sẽ kết thúc bằng văn bản.

driver.current_url
29

Chúng tôi có thể gửi đầu vào bàn phím tới hộp văn bản trên trang web trong Selenium webdriver bằng Python bằng phương thức send_keys. Văn bản được nhập được truyền dưới dạng tham số cho phương thức đó

Để thực hiện các thao tác trên bàn phím, chúng ta cũng có thể sử dụng phương thức send_keys rồi truyền vào lớp Keys. như một tham số cho phương pháp đó. Để sử dụng lớp Keys, chúng ta phải thêm từ selen. webdriver. phổ thông. keys nhập câu lệnh Keys vào mã

cú pháp

i = driver.find_element_by_name["txt"]
i.send_keys["Selenium"]
i.send_keys[Keys.RETURN]

Hãy để chúng tôi thử gửi đầu vào bàn phím tới hộp văn bản trên một trang -

Ví dụ

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
#set chromodriver.exe path
driver = webdriver.Chrome[executable_path="C:\chromedriver.exe"]
driver.implicitly_wait[0.5]
#launch URL
driver.get["//www.google.com/"]
#identify text box
l = driver.find_element_by_class_name["gLFyf"]
#send input
l.send_keys["Selenium"]
#send keyboard input
l.send_keys[Keys.RETURN]

đầu ra

Các định nghĩa API trong chương này hiển thị vị trí tuyệt đối của các lớp. Tuy nhiên, kiểu nhập được đề xuất như dưới đây

from selenium import webdriver

Sau đó, bạn có thể truy cập các lớp học như thế này

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy

Lớp khóa đặc biệt [

menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
2] có thể được nhập như thế này

from selenium.webdriver.common.keys import Keys

Các lớp ngoại lệ có thể được nhập như thế này [Thay thế

menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
3 bằng tên lớp thực tế được cung cấp bên dưới]

from selenium.common.exceptions import [TheNameOfTheExceptionClass]

Các quy ước được sử dụng trong API

Một số thuộc tính có thể gọi được [hoặc phương thức] và các thuộc tính khác không thể gọi được [thuộc tính]. Tất cả các thuộc tính có thể gọi được kết thúc bằng dấu ngoặc tròn

Đây là một ví dụ cho tài sản

  • current_url

    URL của trang hiện đang được tải

    Cách sử dụng

    ________số 8

Đây là một ví dụ về một phương pháp

  • đóng lại[]

    Đóng cửa sổ hiện tại

    Cách sử dụng

    driver.close[]
    

7. 1. ngoại lệ

Các ngoại lệ có thể xảy ra trong tất cả mã webdriver

ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
5 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ]

căn cứ.

Không thể hoàn thành lệnh Nhấp vào phần tử vì phần tử nhận các sự kiện đang che khuất phần tử được yêu cầu nhấp vào

ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
8 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ]

căn cứ.

Bị ném khi một phần tử có mặt trong DOM nhưng các tương tác với phần tử đó sẽ ảnh hưởng đến phần tử khác do thứ tự sơn

ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
#set chromodriver.exe path
driver = webdriver.Chrome[executable_path="C:\chromedriver.exe"]
driver.implicitly_wait[0.5]
#launch URL
driver.get["//www.google.com/"]
#identify text box
l = driver.find_element_by_class_name["gLFyf"]
#send input
l.send_keys["Selenium"]
#send keyboard input
l.send_keys[Keys.RETURN]
51 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ]

căn cứ.

Bị ném khi cố gắng chọn một phần tử không thể chọn

Ví dụ: chọn phần tử 'script'

ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
#set chromodriver.exe path
driver = webdriver.Chrome[executable_path="C:\chromedriver.exe"]
driver.implicitly_wait[0.5]
#launch URL
driver.get["//www.google.com/"]
#identify text box
l = driver.find_element_by_class_name["gLFyf"]
#send input
l.send_keys["Selenium"]
#send keyboard input
l.send_keys[Keys.RETURN]
54 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ]

căn cứ.

Bị ném khi một phần tử có mặt trên DOM, nhưng nó không hiển thị và do đó không thể tương tác với

Thường gặp nhất khi cố gắng nhấp hoặc đọc văn bản của một phần tử bị ẩn khỏi chế độ xem

ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
#set chromodriver.exe path
driver = webdriver.Chrome[executable_path="C:\chromedriver.exe"]
driver.implicitly_wait[0.5]
#launch URL
driver.get["//www.google.com/"]
#identify text box
l = driver.find_element_by_class_name["gLFyf"]
#send input
l.send_keys["Selenium"]
#send keyboard input
l.send_keys[Keys.RETURN]
57 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ]

căn cứ.

Bị ném khi kích hoạt công cụ IME không thành công

ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
from selenium import webdriver
10 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ]

căn cứ.

Bị ném khi không có hỗ trợ IME. Ngoại lệ này được đưa ra cho mọi cuộc gọi phương thức liên quan đến IME nếu hỗ trợ IME không khả dụng trên máy

ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
from selenium import webdriver
13 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ]

căn cứ.

Điều hướng khiến tác nhân người dùng gặp cảnh báo chứng chỉ, thường là do chứng chỉ TLS hết hạn hoặc không hợp lệ

ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
from selenium import webdriver
16 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ]

căn cứ.

Các đối số được chuyển đến một lệnh không hợp lệ hoặc không đúng định dạng

ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
from selenium import webdriver
19 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ]

căn cứ.

Bị ném khi cố gắng thêm cookie trong một tên miền khác với URL hiện tại

ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
02 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ]

căn cứ.

Các tọa độ được cung cấp cho hoạt động của một tương tác không hợp lệ

ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
05 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ]

căn cứ.

Bị ném khi lệnh không thể hoàn thành vì phần tử ở trạng thái không hợp lệ

Điều này có thể do cố gắng xóa một phần tử không thể chỉnh sửa và đặt lại được

ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
08 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ]

căn cứ.

Bị ném khi bộ chọn được sử dụng để tìm phần tử không trả về WebElement. Hiện tại điều này chỉ xảy ra khi bộ chọn là một biểu thức xpath và nó không hợp lệ về mặt cú pháp [i. e. nó không phải là biểu thức xpath] hoặc biểu thức không chọn WebElements [e. g. “đếm[//đầu vào]”]

ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
11 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ]

căn cứ.

Xảy ra nếu id phiên đã cho không có trong danh sách các phiên đang hoạt động, nghĩa là phiên đó không tồn tại hoặc không hoạt động

ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
14 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ]

căn cứ.

Bị ném khi mục tiêu khung hoặc cửa sổ được chuyển đổi không tồn tại

ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
17 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ]

căn cứ.

Đã xảy ra lỗi khi thực thi JavaScript do người dùng cung cấp

ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
20 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ]

căn cứ.

Bị ném khi mục tiêu được cung cấp cho phương thức ActionsChains move[] không hợp lệ, tôi. e. hết tài liệu

ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
23 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ]

căn cứ.

Bị ném khi chuyển sang không có cảnh báo

Điều này có thể xảy ra bằng cách gọi một thao tác trên lớp Alert[] khi chưa có cảnh báo trên màn hình

ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
26 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ]

căn cứ.

Bị ném khi không tìm thấy thuộc tính của phần tử

Bạn có thể muốn kiểm tra xem thuộc tính có tồn tại trong trình duyệt cụ thể mà bạn đang kiểm tra không. Một số trình duyệt có thể có các tên thuộc tính khác nhau cho cùng một thuộc tính. [của IE8. văn bản bên trong so với. firefox. nội dung văn bản]

ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
29 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ]

căn cứ.

Không tìm thấy cookie nào khớp với tên đường dẫn đã cho trong số các cookie được liên kết của tài liệu đang hoạt động trong bối cảnh duyệt web hiện tại

ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
32 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ]

căn cứ.

Ném khi không tìm thấy phần tử

Nếu bạn gặp phải ngoại lệ này, bạn có thể muốn kiểm tra những điều sau đây
  • Kiểm tra bộ chọn của bạn được sử dụng trong find_by…
  • Phần tử có thể chưa xuất hiện trên màn hình tại thời điểm thực hiện thao tác tìm, [trang web vẫn đang tải] xem Selenium. webdriver. hỗ trợ. đợi đã. WebDriverWait[] để biết cách viết trình bao bọc chờ để chờ một phần tử xuất hiện
ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
35 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ]

căn cứ.

Bị ném khi mục tiêu khung được chuyển đổi không tồn tại

ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
38 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ]

căn cứ.

Bị ném khi cố gắng truy cập vào gốc bóng tối của một phần tử khi nó không có gốc bóng tối đi kèm

ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
41 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ]

căn cứ.

Bị ném khi mục tiêu cửa sổ được chuyển đổi không tồn tại

Để tìm bộ điều khiển cửa sổ đang hoạt động hiện tại, bạn có thể lấy danh sách các điều khiển cửa sổ đang hoạt động theo cách sau

from selenium.webdriver.common.keys import Keys
6

ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
44 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ]

căn cứ.

Không thể chụp ảnh màn hình

ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
47 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ]

căn cứ.

Xảy ra khi xảy ra sự cố tương tác với trình quản lý Selenium

ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
50 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ]

căn cứ.

Không thể tạo phiên mới

ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
53 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ]

căn cứ.

Bị ném khi một tham chiếu đến một phần tử hiện đã "cũ"

Cũ có nghĩa là phần tử không còn xuất hiện trên DOM của trang

Nguyên nhân có thể của StaleElementReferenceException bao gồm, nhưng không giới hạn ở
  • Bạn không còn ở trên cùng một trang hoặc trang có thể đã được làm mới kể từ khi phần tử được định vị
  • Phần tử có thể đã bị xóa và thêm lại vào màn hình vì nó được định vị. Chẳng hạn như một yếu tố được di dời. Điều này thường xảy ra với khung javascript khi các giá trị được cập nhật và nút được xây dựng lại
  • Phần tử có thể nằm trong khung nội tuyến hoặc ngữ cảnh khác đã được làm mới
ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
56 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ]

căn cứ.

Bị ném khi một lệnh không hoàn thành trong đủ thời gian

ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
59 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ]

căn cứ.

Bị ném khi trình điều khiển không đặt được cookie

ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
62 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có, alert_text. Tùy chọn[str] = Không có ]

căn cứ.

Ném khi một cảnh báo bất ngờ đã xuất hiện

Thường xuất hiện khi một phương thức không mong muốn đang chặn trình quản trị web thực thi các lệnh

______364 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có, alert_text. Tùy chọn[str] = Không có ] → Không có

Tự khởi tạo. Xem help[type[self]] để có chữ ký chính xác

ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
66 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ]

căn cứ.

Bị ném khi một lớp hỗ trợ không nhận được phần tử web mong muốn

ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
69 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ]

căn cứ.

Lệnh được yêu cầu khớp với một URL đã biết nhưng không khớp với bất kỳ phương thức nào cho URL đó

ngoại lệ
menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]
4
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
72 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ]

căn cứ.

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
73

Ngoại lệ webdriver cơ sở

______364 [ tin nhắn. Tùy chọn[str] = Không, màn hình. Tùy chọn[str] = Không có, stacktrace. Tùy chọn[Sequence[str]] = Không có ] → Không có

Tự khởi tạo. Xem help[type[self]] để có chữ ký chính xác

7. 2. chuỗi hành động

Việc triển khai ActionChains,

hạng
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
75
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
76 [ trình điều khiển, thời lượng=250 ]

căn cứ.

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
77

ActionChains là một cách để tự động hóa các tương tác cấp thấp như di chuyển chuột, thao tác với nút chuột, nhấn phím và tương tác với menu ngữ cảnh. Điều này hữu ích để thực hiện các hành động phức tạp hơn như di chuột qua và kéo và thả

Tạo hành động của người dùng. Khi bạn gọi các phương thức cho các hành động trên đối tượng ActionChains, các hành động được lưu trữ trong một hàng đợi trong đối tượng ActionChains. Khi bạn gọi thực hiện [], các sự kiện được kích hoạt theo thứ tự chúng được xếp hàng đợi

ActionChains có thể được sử dụng trong một mẫu chuỗi

menu = driver.find_element[By.CSS_SELECTOR, ".nav"]
hidden_submenu = driver.find_element[By.CSS_SELECTOR, ".nav #submenu1"]

ActionChains[driver].move_to_element[menu].click[hidden_submenu].perform[]

Hoặc các hành động có thể được xếp hàng từng cái một, sau đó được thực hiện

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
#set chromodriver.exe path
driver = webdriver.Chrome[executable_path="C:\chromedriver.exe"]
driver.implicitly_wait[0.5]
#launch URL
driver.get["//www.google.com/"]
#identify text box
l = driver.find_element_by_class_name["gLFyf"]
#send input
l.send_keys["Selenium"]
#send keyboard input
l.send_keys[Keys.RETURN]
5

Dù bằng cách nào, các hành động được thực hiện theo thứ tự chúng được gọi, lần lượt

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
64 [ trình điều khiển, thời lượng=250 ]

Tạo một ActionChains mới

lập luận
  • người lái xe. Phiên bản WebDriver thực hiện hành động của người dùng
  • khoảng thời gian. ghi đè 250 mili giây mặc định của DEFAULT_MOVE_DURATION trong PointerInput
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
79 [ on_element=None ]

Nhấp vào một yếu tố

lập luận
  • on_element. Phần tử để nhấp. Nếu Không, hãy nhấp vào vị trí chuột hiện tại
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
80 [ on_element=None ]

Giữ chuột trái trên một phần tử

lập luận
  • on_element. Phần tử để di chuột xuống. Nếu Không, hãy nhấp vào vị trí chuột hiện tại
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
81 [ on_element=None ]

Thực hiện nhấp chuột phải [nhấp chuột phải] vào một phần tử

lập luận
  • on_element. Phần tử để nhấp vào ngữ cảnh. Nếu Không, hãy nhấp vào vị trí chuột hiện tại
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
82 [ on_element=None ]

Bấm đúp vào một phần tử

lập luận
  • on_element. Phần tử để nhấp đúp. Nếu Không, hãy nhấp vào vị trí chuột hiện tại
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
83 [ nguồn, đích ] Nhấn giữ . lập luận.
  • nguồn. Phần tử để di chuột xuống
  • Mục tiêu. Phần tử để di chuột lên
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
84 [ nguồn, xoffset, yoffset ] Giữ . lập luận.
  • nguồn. Phần tử để di chuột xuống
  • xoffset. X bù để di chuyển đến
  • yoffset. Y offset để di chuyển đến
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
85 [ value, element=None ] Gửi . Chỉ nên được sử dụng với các phím bổ trợ [Control, Alt và Shift]. lập luận.
  • giá trị. Phím bổ trợ để gửi. Các giá trị được định nghĩa trong lớp Keys
  • thành phần. Phần tử để gửi khóa. Nếu Không có, gửi một khóa đến phần tử tập trung hiện tại

Ví dụ, nhấn ctrl+c

from selenium import webdriver
1

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
86 [ value, element=None ]

Phát hành một phím bổ trợ

lập luận
  • giá trị. Phím bổ trợ để gửi. Các giá trị được định nghĩa trong lớp Keys
  • thành phần. Phần tử để gửi khóa. Nếu Không có, gửi một khóa đến phần tử tập trung hiện tại

Ví dụ, nhấn ctrl+c

from selenium import webdriver
1

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
87 [ xoffset, yoffset ]

Di chuyển chuột đến vị trí lệch khỏi vị trí chuột hiện tại

lập luận
  • xoffset. Độ lệch X để di chuyển đến, dưới dạng số nguyên dương hoặc âm
  • yoffset. Độ lệch Y để di chuyển đến, dưới dạng số nguyên dương hoặc âm
______388 [ to_element ]

Di chuyển chuột đến giữa một phần tử

lập luận
  • to_element. WebElement để di chuyển đến
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
89 [ to_element, xoffset, yoffset ] Di chuyển . Độ lệch có liên quan đến góc trên cùng bên trái của phần tử. lập luận.
  • to_element. WebElement để di chuyển đến
  • xoffset. X bù để di chuyển đến
  • yoffset. Y offset để di chuyển đến
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
90 [ giây ]

Tạm dừng tất cả đầu vào trong khoảng thời gian đã chỉ định tính bằng giây

______391 []

Thực hiện tất cả các hành động được lưu trữ

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
92 [ on_element=None ]

Nhả một nút chuột đang giữ trên một phần tử

lập luận
  • on_element. Phần tử để di chuột lên. Nếu Không có, nhả ở vị trí chuột hiện tại
______393 []

Xóa các hành động đã được lưu trữ cục bộ và trên đầu từ xa

______394 [ x. int, y. int, delta_x. int, delta_y. int, thời lượng. int = 0, nguồn gốc. str = 'khung nhìn' ]

Gửi thông tin cuộn bánh xe tới trình duyệt để xử lý

lập luận
  • x. tọa độ X bắt đầu
  • y. tọa độ Y bắt đầu
  • delta_x. khoảng cách chuột sẽ cuộn trên trục x
  • delta_y. khoảng cách chuột sẽ cuộn trên trục y
______395 [ delta_x. int, delta_y. int ]

Cuộn theo số lượng được cung cấp với điểm gốc ở góc trên cùng bên trái của chế độ xem

lập luận
  • delta_x. Khoảng cách dọc theo trục X để cuộn bằng bánh xe. Giá trị âm cuộn sang trái
  • delta_y. Khoảng cách dọc theo trục Y để cuộn bằng bánh xe. Một giá trị âm cuộn lên
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
96 [ scroll_origin. selen. webdriver. phổ thông. hành động. bánh xe_input. ScrollOrigin, delta_x. int, delta_y. int ]

Cuộn theo số lượng được cung cấp dựa trên nguồn gốc được cung cấp. Điểm gốc cuộn là tâm của một phần tử hoặc phía trên bên trái của chế độ xem cộng với bất kỳ độ lệch nào. Nếu nguồn gốc là một phần tử và phần tử không có trong chế độ xem, phần dưới cùng của phần tử trước tiên sẽ được cuộn xuống dưới cùng của chế độ xem

lập luận
  • nguồn gốc. Nơi cuộn bắt nguồn [khung nhìn hoặc trung tâm thành phần] cộng với độ lệch được cung cấp
  • delta_x. Khoảng cách dọc theo trục X để cuộn bằng bánh xe. Giá trị âm cuộn sang trái
  • delta_y. Khoảng cách dọc theo trục Y để cuộn bằng bánh xe. Một giá trị âm cuộn lên
Tăng. Nếu nguồn gốc với phần bù nằm ngoài chế độ xem. - MoveTargetOutOfBoundsException - Nếu điểm gốc có phần bù nằm ngoài chế độ xem. Phần tử
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
97 [ . selen. webdriver. Xa xôi. phần tử web. Phần tử web ]

Nếu phần tử nằm ngoài khung nhìn, hãy cuộn phần dưới cùng của phần tử xuống cuối khung nhìn

lập luận
  • thành phần. Phần tử nào để cuộn vào khung nhìn
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
98 [ *keys_to_send ]

Gửi các phím đến phần tử tập trung hiện tại

lập luận
  • keys_to_send. Các phím để gửi. Các hằng số phím bổ trợ có thể được tìm thấy trong lớp 'Phím'
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
99 [ element, *keys_to_send ]

Gửi khóa đến một phần tử

lập luận
  • thành phần. Phần tử để gửi khóa
  • keys_to_send. Các phím để gửi. Các hằng số phím bổ trợ có thể được tìm thấy trong lớp 'Phím'

7. 3. cảnh báo

Việc thực hiện cảnh báo

hạng
from selenium.webdriver.common.keys import Keys
00
from selenium.webdriver.common.keys import Keys
01 [ trình điều khiển ]

căn cứ.

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
77

Cho phép làm việc với các cảnh báo

Sử dụng lớp này để tương tác với lời nhắc cảnh báo. Nó chứa các phương thức để loại bỏ, chấp nhận, nhập và nhận văn bản từ lời nhắc cảnh báo

Chấp nhận / Loại bỏ lời nhắc cảnh báo

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
1

Nhập giá trị vào dấu nhắc cảnh báo

name_prompt = Cảnh báo [trình điều khiển] name_prompt. send_keys[“William Shakespeare”] nhắc tên. Chấp nhận[]

Đọc văn bản của lời nhắc xác minh

alert_text = Cảnh báo [trình điều khiển]. văn bản tự. assertEqual[“Bạn có muốn thoát không?”, alert_text]

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
64 [ trình điều khiển ]

Tạo Cảnh báo mới

lập luận
  • người lái xe. Phiên bản WebDriver thực hiện hành động của người dùng
______504 []

Chấp nhận cảnh báo có sẵn

Cách sử dụng. Cảnh báo [người lái xe]. accept[] # Xác nhận hộp thoại cảnh báo

______505 []

Loại bỏ cảnh báo có sẵn

______398 [ keysToSend ]

Gửi chìa khóa đến cảnh báo

lập luận
  • phímĐể gửi. Văn bản gửi tới Alert
from selenium.webdriver.common.keys import Keys
07

Nhận văn bản của Cảnh báo

7. 4. Phím đặc biệt

Việc thực hiện các phím

lớp
from selenium.webdriver.common.keys import Keys
08
from selenium.webdriver.common.keys import Keys
09

căn cứ.

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
77

Bộ mã khóa đặc biệt

from selenium.webdriver.common.keys import Keys
11 = '\ue025'
from selenium.webdriver.common.keys import Keys
12 = '\ue00a'
from selenium.webdriver.common.keys import Keys
13 = '\ue015'
from selenium.webdriver.common.keys import Keys
14 = '\ue012'
from selenium.webdriver.common.keys import Keys
15 = '\ue014'
from selenium.webdriver.common.keys import Keys
16 = '\ue013'
from selenium.webdriver.common.keys import Keys
17 = '\ue003'
from selenium.webdriver.common.keys import Keys
18 = '\ue003'
from selenium.webdriver.common.keys import Keys
19 =

7. 5. Xác định vị trí các phần tử theo

Đây là những thuộc tính có thể được sử dụng để định vị các phần tử. Xem chương để biết cách sử dụng ví dụ

Bằng cách thực hiện

lớp ________ 576 ________ 577

căn cứ.

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
77

Tập hợp các chiến lược định vị được hỗ trợ

from selenium.webdriver.common.keys import Keys
79 = 'tên lớp'_______580 = 'bộ chọn css'
from selenium.webdriver.common.keys import Keys
81 = 'id'
from selenium.webdriver.common.keys import Keys
82 = 'văn bản liên kết'
from selenium.webdriver.common.keys import Keys
83 = 'tên'
from selenium.webdriver.common.keys import Keys
84 = 'văn bản liên kết một phần'
from selenium.webdriver.common.keys import Keys
85 = 'tên thẻ'
from selenium.webdriver.common.keys import Keys
86 = 'xpath'

7. 6. Khả năng mong muốn

Xem phần ví dụ về cách sử dụng các khả năng mong muốn

Triển khai Khả năng mong muốn

lớp
from selenium.webdriver.common.keys import Keys
87____588

căn cứ.

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
77

Tập hợp các khả năng mong muốn được hỗ trợ mặc định

Sử dụng điểm này làm điểm bắt đầu để tạo đối tượng khả năng mong muốn để yêu cầu trình điều khiển web từ xa kết nối với máy chủ Selenium hoặc lưới Selenium

Ví dụ sử dụng

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
2

Ghi chú. Luôn luôn sử dụng '. copy[]’ trên đối tượng DesiredCapabilities để tránh tác dụng phụ của việc thay đổi thể hiện của lớp Toàn cầu

from selenium.webdriver.common.keys import Keys
90 = {'tên trình duyệt'. 'chrome'}____591 = {'tên trình duyệt'. 'MicrosoftEdge'}____592 = {'acceptInsecureCerts'. Đúng, 'tên trình duyệt'. 'firefox', 'moz. trình gỡ lỗiAddress'. Đúng
from selenium.webdriver.common.keys import Keys
93 = {'tên trình duyệt'. 'htmlunit', 'nền tảng'. 'BẤT CỨ', 'phiên bản'. ''}____594 = {'tên trình duyệt'. 'htmlđơn vị', 'javascriptEnabled'. Đúng, 'nền tảng'. 'BẤT CỨ', 'phiên bản'. 'firefox'}____595 = {'browserName'. 'internet explorer', 'platformName'. 'cửa sổ'}____596 = {'tên trình duyệt'. 'iPad', 'nền tảng'. 'mac', 'phiên bản'. ''}____597 = {'tên trình duyệt'. 'iPhone', 'nền tảng'. 'mac', 'phiên bản'. ''}____598 = {'tên trình duyệt'. 'safari', 'tên nền tảng'. 'mac'}____599 = {'tên trình duyệt'. 'Trình duyệt nhỏ', 'nền tảng'. 'BẤT CỨ', 'phiên bản'. ''}____700 = {'tên trình duyệt'. 'Trình duyệt nhỏ', 'nền tảng'. 'BẤT CỨ', 'phiên bản'. ''}

7. 7. Thao tác chạm

7. 8. Ủy quyền

Việc triển khai Proxy

lớp
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
01____702 [ raw=None ]

căn cứ.

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
77

Proxy chứa thông tin về loại proxy và cài đặt proxy cần thiết

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
64 [ raw=None ]

Tạo một Proxy mới

lập luận
  • thô. dữ liệu proxy thô. Nếu Không, giá trị lớp mặc định được sử dụng
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
05 [ khả năng ]

Thêm thông tin proxy dưới dạng khả năng trong các khả năng được chỉ định

lập luận
  • khả năng. Các khả năng mà proxy sẽ được thêm vào
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
06

Trả về cài đặt tự động phát hiện

________ 707 = Sai ________ 708 = ''______ 709

Trả về cài đặt proxy ftp

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
10 = ''
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
11

Trả về cài đặt proxy http

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
12 = ''
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
13

Trả về cài đặt noproxy

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
14 = ''
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
15 = {'ff_value'. 6, 'chuỗi'. 'KHÔNG XÁC ĐỊNH'}____716

Trả về cài đặt url tự động cấu hình proxy

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
17

Trả về loại proxy là ProxyType

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
18 = ''
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
19 = ''
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
20 = ''
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
21 = Không có
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
22

Trả về cài đặt mật khẩu proxy vớ

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
23

Trả về cài đặt proxy vớ

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
24

Trả về cài đặt tên người dùng proxy vớ

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
25

Trả về cài đặt phiên bản proxy của tất

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
26 = ''______727

Trả về cài đặt proxy https

lớp
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
01
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
29

căn cứ.

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
77

Tập hợp các loại proxy có thể

Mỗi loại proxy có 2 thuộc tính. 'ff_value' là giá trị của tùy chọn cấu hình Firefox, 'chuỗi' là id của loại proxy. classmethod
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
31 [ value ]
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
32 = {'ff_value'. 4, 'chuỗi'. 'AUTODETECT'}
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
33 = {'ff_value'. 0, 'chuỗi'. 'TRỰC TIẾP'}____734 = {'ff_value'. 1, 'chuỗi'. 'THỦ CÔNG'}____735 = {'ff_value'. 2, 'chuỗi'. 'PAC'}____736 = {'ff_value'. 3, 'chuỗi'. 'RESERVED1'}____737 = {'ff_value'. 5, 'chuỗi'. 'HỆ THỐNG'}____738 = {'ff_value'. 6, 'chuỗi'. 'KHÔNG ĐƯỢC XÁC ĐỊNH'}lớp
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
01
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
40

căn cứ.

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
77

Nhà máy cho các loại proxy

_______742 tĩnh [ ff_value, string ]

7. 9. tiện ích

Các phương thức Utils

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
43
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
44 [ máy chủ. Liên minh [str, byte, bytearray, Không], cổng. Tùy chọn[int] = Không có ] → Tùy chọn[str]

Phân giải tên máy chủ thành IP, ưu tiên địa chỉ IPv4

Chúng tôi thích IPv4 hơn để chúng tôi không thay đổi hành vi so với các triển khai chỉ dành cho IPv4 trước đó và vì một số trình điều khiển [e. g. , FirefoxDriver] không hỗ trợ kết nối IPv6

Nếu số cổng tùy chọn được cung cấp, chỉ những IP lắng nghe trên cổng nhất định mới được xem xét

lập luận
  • máy chủ - Tên máy chủ
  • cổng - Số cổng tùy chọn
trả lại

Một địa chỉ IP duy nhất, dưới dạng một chuỗi. Nếu tìm thấy bất kỳ địa chỉ IPv4 nào, một địa chỉ sẽ được trả lại. Mặt khác, nếu tìm thấy bất kỳ địa chỉ IPv6 nào, một địa chỉ sẽ được trả lại. Nếu không, thì Không được trả lại

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
43
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
46 [] → int

Xác định một cổng miễn phí bằng cách sử dụng ổ cắm

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
43
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
48 [ cổng. int, máy chủ. Tùy chọn[str] = 'máy chủ cục bộ' ] → bool

Cố gắng kết nối với máy chủ tại cổng để xem nó có chạy không

lập luận
  • port - Cổng để kết nối
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
43
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
50 [ cổng. Union[int, str] ] → bool

Cố gắng kết nối với máy chủ HTTP tại đường dẫn /status và cổng được chỉ định để xem nó có phản hồi thành công không

lập luận
  • port - Cổng để kết nối
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
43
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
52 [ máy chủ. đường, cổng. int ] → str

Tham gia một tên máy chủ và cổng với nhau

Đây là một triển khai tối thiểu nhằm đối phó với các chữ cái IPv6. Ví dụ: _join_host_port[‘. 1’, 80] == ‘[. 1]. 80’

lập luận
  • máy chủ - Tên máy chủ
  • cổng - Một cổng số nguyên
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
43
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
54 [ giá trị. Iterable[Union[str, int, float]] ] → Danh sách[str]

Xử lý các giá trị sẽ được nhập vào phần tử

7. 10. Dịch vụ

lớp
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
55_______756 [ có thể thực thi được. đường, cảng. int = 0, log_file. Liên minh [int, IO [Bất kỳ]] = -3, env. Tùy chọn[Ánh xạ[Bất kỳ, Bất kỳ]] = Không, start_error_message. Tùy chọn[str] = Không có ]

căn cứ.

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
57

Lớp cơ sở trừu tượng cho tất cả các đối tượng dịch vụ. Các dịch vụ thường khởi chạy một chương trình con trong một quy trình mới dưới dạng quy trình tạm thời để giao tiếp với trình duyệt

Thông số
  • thực thi – đường dẫn cài đặt của tệp thực thi
  • cổng – Cổng để dịch vụ chạy, mặc định là 0 nơi hệ điều hành sẽ quyết định
  • log_file – [Tùy chọn] bộ mô tả tệp [pos int] hoặc đối tượng tệp có bộ mô tả tệp hợp lệ. quy trình con. PIPE & quy trình con. DEVNULL cũng là các giá trị hợp lệ
  • env – [Tùy chọn] Ánh xạ các biến môi trường cho quy trình mới, mặc định là os. môi trường
______364 [ có thể thực thi được. đường, cổng. int = 0, log_file. Liên minh [int, IO [Bất kỳ]] = -3, env. Tùy chọn[Ánh xạ[Bất kỳ, Bất kỳ]] = Không, start_error_message. Tùy chọn[str] = Không có ] → Không có

Tự khởi tạo. Xem help[type[self]] để có chữ ký chính xác

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
59 [] → Không có

Kiểm tra xem quá trình cơ bản vẫn đang chạy

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
60 [] → Danh sách[str]

Danh sách các đối số chương trình [không bao gồm tệp thực thi]

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
48 [] → bool

Thiết lập kết nối ổ cắm để xác định xem dịch vụ đang chạy trên cổng có thể truy cập được không

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
62 [] → Không có

Gửi một yêu cầu HTTP đến điểm cuối tắt máy cho dịch vụ nhằm ngăn chặn nó

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
63 [] → Không có

Bắt đầu dịch vụ

ngoại lệ
  • WebDriverException. Tăng lên khi không thể khởi động dịch vụ hoặc khi không thể kết nối với dịch vụ
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
64 [] → Không có

Dừng dịch vụ

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
65

Nhận url của Dịch vụ

7. 11. Bộ đệm ứng dụng

Triển khai ApplicationCache

hạng
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
66_______767 [ tài xế ]

căn cứ.

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
77

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
64 [ trình điều khiển ]

Tạo bộ đệm ứng dụng mới

lập luận
  • người lái xe. Phiên bản WebDriver thực hiện hành động của người dùng
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
70 = 2
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
71 = 3
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
72 = 1
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
73 = 5
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
74 = 0
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
75 = 4
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
76

Trả về trạng thái hiện tại của bộ đệm ứng dụng

7. 12. Trình điều khiển web Firefox

lớp
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
77_______778 [ firefox_profile=Không, firefox_binary=Không, khả năng=Không, proxy=Không, executable_path='geckodriver', options= . log', service_args=None, service=None, wish_capabilities=None, log_path=None, keep_alive=True ]

căn cứ.

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
64 [ firefox_profile=Không, firefox_binary=Không, khả năng=Không, proxy=Không, executable_path='geckodriver', options=Không . log', service_args=None, service=None, wish_capabilities=None, log_path=None, keep_alive=True ]

Bắt đầu phiên cục bộ mới của Firefox

Dựa trên sự kết hợp và tính đặc hiệu của các đối số từ khóa khác nhau, một từ điển khả năng sẽ được xây dựng để chuyển đến đầu từ xa

Các đối số từ khóa được cung cấp cho hàm tạo này là công cụ trợ giúp để cho phép tùy chỉnh phiên Firefox WebDriver dễ dàng hơn với các tùy chọn khác nhau. Chúng được ánh xạ tới một từ điển khả năng được chuyển đến đầu từ xa

Như một số tùy chọn, chẳng hạn như firefox_profile và các tùy chọn. cấu hình là loại trừ lẫn nhau, ưu tiên được đưa ra từ mức độ cụ thể của cài đặt. khả năng là đối số từ khóa ít cụ thể nhất, tiếp theo là tùy chọn, tiếp theo là firefox_binary và firefox_profile

Trong thực tế, điều này có nghĩa là nếu firefox_profile và các tùy chọn. hồ sơ đều được đặt, phiên bản hồ sơ đã chọn sẽ luôn đến từ biến cụ thể nhất. Trong trường hợp này sẽ là firefox_profile. Điều này sẽ dẫn đến các tùy chọn. profile bị bỏ qua vì nó được coi là cài đặt ít cụ thể hơn so với đối số từ khóa firefox_profile cấp cao nhất. Tương tự, nếu bạn đã chỉ định một khả năng[“moz. firefoxOptions”][“profile”] Chuỗi Base64, chuỗi này sẽ xếp hạng bên dưới các tùy chọn. Hồ sơ

Thông số
  • firefox_profile – Không dùng nữa. Thể hiện của đối tượng
    from selenium.common.exceptions import [TheNameOfTheExceptionClass]
    
    81 hoặc một chuỗi. Nếu không được xác định, một hồ sơ mới sẽ được tạo ở một vị trí tạm thời trên hệ thống
  • firefox_binary – Không dùng nữa. Phiên bản của
    from selenium.common.exceptions import [TheNameOfTheExceptionClass]
    
    82 hoặc đường dẫn đầy đủ đến nhị phân Firefox. Nếu không được xác định, cài đặt Firefox mặc định của hệ thống sẽ được sử dụng
  • khả năng – Không dùng nữa. Từ điển các khả năng mong muốn
  • proxy – Không dùng nữa. Cài đặt proxy sẽ sử dụng khi giao tiếp với Firefox qua kết nối tiện ích mở rộng
  • executable_path – Không dùng nữa. Đường dẫn đầy đủ để ghi đè mã nhị phân tắc kè nào sẽ sử dụng cho Firefox 47. 0. 1 trở lên, mặc định chọn tệp nhị phân từ đường dẫn hệ thống
  • tùy chọn - Trường hợp của
    from selenium.common.exceptions import [TheNameOfTheExceptionClass]
    
    83
  • dịch vụ – [Tùy chọn] phiên bản dịch vụ để quản lý khởi động và dừng trình điều khiển
  • service_log_path – Không dùng nữa. Nơi đăng nhập thông tin từ trình điều khiển
  • service_args – Không dùng nữa. Danh sách các đối số để chuyển đến dịch vụ trình điều khiển
  • wish_capabilities – Không dùng nữa. bí danh của khả năng. Trong các phiên bản tương lai của thư viện này, điều này sẽ thay thế 'khả năng'. Điều này sẽ làm cho chữ ký phù hợp với RemoteWebDriver
  • keep_alive – Có định cấu hình remote_connection hay không. RemoteConnection để sử dụng HTTP keep-alive
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
84 [ bối cảnh ]

Đặt bối cảnh mà các lệnh Selenium đang chạy bằng cách sử dụng câu lệnh with. Trạng thái của bối cảnh trên máy chủ được lưu trước khi vào khối và được khôi phục khi thoát khỏi nó

Thông số. bối cảnh – Bối cảnh, có thể là một trong các thuộc tính của lớp CONTEXT_CHROME hoặc CONTEXT_CONTENT

Ví dụ sử dụng

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
3

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
85 [] → strLấy toàn bộ ảnh chụp màn hình tài liệu của cửa sổ hiện tại dưới dạng chuỗi mã hóa base64 mà . Cách sử dụng.

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
4

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
86 [ tên tệp ] → boolLưu toàn bộ tài liệu . Trả về Sai nếu có bất kỳ IOError nào, ngược lại trả về Đúng. Sử dụng đường dẫn đầy đủ trong tên tệp của bạn. lập luận.
  • tên tập tin. Đường dẫn đầy đủ mà bạn muốn lưu ảnh chụp màn hình của mình vào. Điều này sẽ kết thúc với một. phần mở rộng png
Cách sử dụng

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
5

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
87 [] → byte

Lấy toàn bộ ảnh chụp màn hình tài liệu của cửa sổ hiện tại dưới dạng dữ liệu nhị phân

Cách sử dụng

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
6

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
88 [ đường dẫn, tạm thời=Sai ]

Cài đặt tiện ích Firefox

Trả về định danh của addon đã cài đặt. Mã định danh này sau này có thể được sử dụng để gỡ cài đặt addon

Thông số

đường dẫn – Đường dẫn tuyệt đối đến addon sẽ được cài đặt

Cách sử dụng

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
7

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
89 [] → Không có

Thoát khỏi trình điều khiển và đóng mọi cửa sổ liên quan

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
90 [ tên tệp ] → boolLưu toàn bộ tài liệu . Trả về Sai nếu có bất kỳ IOError nào, ngược lại trả về Đúng. Sử dụng đường dẫn đầy đủ trong tên tệp của bạn. lập luận.
  • tên tập tin. Đường dẫn đầy đủ mà bạn muốn lưu ảnh chụp màn hình của mình vào. Điều này sẽ kết thúc với một. phần mở rộng png
Cách sử dụng

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
8

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
91 [ bối cảnh ] → Không có
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
92 [identifier] → None

Gỡ cài đặt addon Firefox bằng mã định danh của nó

Cách sử dụng

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
9

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
93 = 'chrome'
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
94 = 'nội dung'
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
95

7. 13. Tùy chọn Firefox WebDriver

lớp
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
96
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
97

căn cứ.

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
77

______364 []

Tự khởi tạo. Xem help[type[self]] để có chữ ký chính xác

driver.current_url
00 [] → dictclass
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
96
driver.current_url
02

căn cứ.

driver.current_url
03

______364 []

Tự khởi tạo. Xem help[type[self]] để có chữ ký chính xác

______805 [ android_package. str = 'tổ chức. mozilla. firefox', android_activity=Không, device_serial=Không ]

Cho phép sử dụng trình duyệt di động cho các trình duyệt hỗ trợ nó

Đối số. android_activity. Tên của gói android để bắt đầu
driver.current_url
06 [ name. str, giá trị. Liên minh[str, int, bool] ]

Đặt tùy chọn

driver.current_url
00 [] → lệnh

Nguyên soái các tùy chọn Firefox thành moz. đối tượng firefoxOptions

driver.current_url
08 = 'moz. firefoxOptions'____809

Trả về phiên bản FirefoxBinary

driver.current_url
10Trả lại. Vị trí nhị phân.
driver.current_url
11

Trả lại các khả năng tối thiểu cần thiết như một từ điển

driver.current_url
12Trả về. Đúng nếu đối số không đầu được đặt, nếu không thì Sai_______813Returns. Một mệnh lệnh của sở thích.
driver.current_url
14Trả lại. Hồ sơ Firefox để sử dụng

7. 14. Hồ sơ Firefox WebDriver

ngoại lệ
driver.current_url
15
driver.current_url
16

căn cứ.

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
73

Ngoại lệ cho các tệp kê khai bổ trợ không được định dạng tốt

lớp
driver.current_url
15_______819 [ profile_directory=None ]

căn cứ.

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
77

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
64 [ profile_directory=None ]

Khởi tạo một phiên bản mới của Hồ sơ Firefox

lập luận
  • hồ sơ_thư mục. Thư mục hồ sơ mà bạn muốn sử dụng. Nếu một thư mục được chuyển vào, nó sẽ được sao chép và thư mục được sao chép sẽ được trình điều khiển sử dụng khi khởi tạo. Điều này mặc định là Không có và sẽ tạo một thư mục mới khi đối tượng được tạo
driver.current_url
22 [ extension='webdriver. xpi' ]
driver.current_url
06 [ khóa, giá trị ]

đặt tùy chọn mà chúng tôi muốn trong hồ sơ

driver.current_url
24 []
driver.current_url
25 = 'WEBDRIVER_ANONYMOUS_PROFILE'
driver.current_url
26 = Không
driver.current_url
27
driver.current_url
28
driver.current_url
29

Chuỗi thư mục hồ sơ được nén, mã hóa base64 để sử dụng với giao thức dây JSON của WebDriver từ xa

driver.current_url
30

Nhận thư mục hồ sơ hiện đang được sử dụng

driver.current_url
31

Nhận cổng mà WebDriver đang hoạt động

7. 15. Firefox WebDriver nhị phân

lớp
driver.current_url
32
driver.current_url
33 [ firefox_path=None, log_file=None ]

căn cứ.

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
77

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
64 [ firefox_path=None, log_file=None ]

Tạo một phiên bản mới của tệp nhị phân Firefox

lập luận
  • firefox_path - Đường dẫn đến tệp thực thi của Firefox. Theo mặc định, nó sẽ được phát hiện từ các vị trí tiêu chuẩn
  • log_file - Một đối tượng tệp để chuyển hướng đầu ra của quy trình firefox sang. Nó có thể là hệ thống. tiêu chuẩn. Xin lưu ý rằng khi chạy song song, đầu ra sẽ không đồng bộ. Theo mặc định, nó sẽ được chuyển hướng đến /dev/null
driver.current_url
36 [ *args ]
driver.current_url
37 []

Giết trình duyệt

Điều này rất hữu ích khi trình duyệt bị kẹt

driver.current_url
38 [ profile, timeout=30 ]

Khởi chạy trình duyệt cho tên hồ sơ đã cho. Giả sử hồ sơ đã tồn tại

driver.current_url
39 [ tên ]

Trả về đường dẫn đủ điều kiện bằng cách tìm kiếm Đường dẫn của tên đã cho

driver.current_url
40 = 'x_ignore_nofocus. Vì thế'

7. 16. Kết nối tiện ích mở rộng Firefox WebDriver

ngoại lệ
driver.current_url
41____842

căn cứ.

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
73

Đã xảy ra lỗi nội bộ trong tiện ích mở rộng

Có thể do đầu vào không tốt hoặc lỗi trong webdriver

lớp
driver.current_url
41
driver.current_url
45 [ máy chủ, firefox_profile, firefox_binary=None, timeout=30 ]

căn cứ.

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
64 [ máy chủ, firefox_profile, firefox_binary=None, timeout=30 ]

Tự khởi tạo. Xem help[type[self]] để có chữ ký chính xác

driver.current_url
48 []

Kết nối với tiện ích mở rộng và truy xuất id phiên

phương thức lớp
driver.current_url
49 []

Kết nối với một trình duyệt đang chạy và thoát ngay lập tức

phương thức lớp
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
48 []

Cố gắng kết nối với tiện ích mở rộng nhưng không truy xuất được ngữ cảnh

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
89 [ sessionId=None ]

7. 17. Trình điều khiển web của Chrome

lớp
driver.current_url
52_______778 [ executable_path='chromedriver', port=0, tùy chọn. selen. webdriver. trình duyệt Chrome. tùy chọn. Tùy chọn = Không có, service_args=Không có, mong muốn_capabilities=Không có, service_log_path=Không có, chrome_options=Không có, dịch vụ. selen. webdriver. trình duyệt Chrome. dịch vụ. Dịch vụ = Không có, keep_alive=Không có ]

căn cứ.

driver.current_url
54

Điều khiển ChromeDriver và cho phép bạn điều khiển trình duyệt. Bạn sẽ cần tải xuống tệp thực thi ChromeDriver từ http. // chromedriver. kho. googleapis. com/chỉ mục. html

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
64 [ executable_path='chromedriver', port=0, tùy chọn. selen. webdriver. trình duyệt Chrome. tùy chọn. Tùy chọn = Không có, service_args=Không có, mong muốn_capabilities=Không có, service_log_path=Không có, chrome_options=Không có, dịch vụ. selen. webdriver. trình duyệt Chrome. dịch vụ. Dịch vụ = Không có, keep_alive=Không có ]

Tạo một phiên bản mới của trình điều khiển chrome. Bắt đầu dịch vụ và sau đó tạo phiên bản mới của trình điều khiển chrome

lập luận
  • executable_path - Không dùng nữa. đường dẫn đến tệp thực thi. Nếu mặc định được sử dụng, nó giả sử tệp thực thi nằm trong $PATH
  • cổng - Không dùng nữa. cổng bạn muốn dịch vụ chạy, nếu để bằng 0, một cổng miễn phí sẽ được tìm thấy
  • tùy chọn - điều này lấy một phiên bản của ChromeOptions
  • dịch vụ - Đối tượng dịch vụ để xử lý trình điều khiển trình duyệt nếu bạn cần chuyển thêm chi tiết
  • service_args - Không dùng nữa. Danh sách các đối số để chuyển đến dịch vụ trình điều khiển
  • wish_capabilities - Không dùng nữa. Đối tượng từ điển chỉ có các khả năng không dành riêng cho trình duyệt, chẳng hạn như “proxy” hoặc “loggingPref”
  • service_log_path - Không dùng nữa. Nơi đăng nhập thông tin từ trình điều khiển
  • keep_alive - Không dùng nữa. Có định cấu hình ChromeRemoteConnection để sử dụng HTTP keep-alive hay không

7. 18. Tùy chọn trình điều khiển web của Chrome

lớp
driver.current_url
56
driver.current_url
02

căn cứ.

driver.current_url
58

______805 [ android_package. str = 'com. Android. chrome', android_activity. Tùy chọn[str] = Không, device_serial. Tùy chọn[str] = Không có ] → Không có

Cho phép sử dụng trình duyệt di động cho các trình duyệt hỗ trợ nó

lập luận. android_activity. Tên của gói Android để bắt đầu
driver.current_url
11

Trả lại các khả năng tối thiểu cần thiết như một từ điển

7. 19. Dịch vụ trình điều khiển web của Chrome

lớp
driver.current_url
61
from selenium.common.exceptions import [TheNameOfTheExceptionClass]
56 [ đường dẫn thực thi. str = 'chromedriver', cổng. int = 0, dịch vụ_args. Tùy chọn[Danh sách[str]] = Không, log_path. Tùy chọn[str] = Không, env. Tùy chọn[Ánh xạ[str, str]] = Không có ]

căn cứ.

driver.current_url
63

Một lớp Dịch vụ chịu trách nhiệm bắt đầu và dừng chromedriver

Thông số
  • executable_path – đường dẫn cài đặt của chromedriver thực thi, mặc định là chromedriver
  • cổng – Cổng để dịch vụ chạy, mặc định là 0 nơi hệ điều hành sẽ quyết định
  • service_args - [Tùy chọn] Danh sách các đối số sẽ được chuyển đến quy trình con khi khởi chạy tệp thực thi
  • log_path – [Tùy chọn] Chuỗi được chuyển đến tệp thực thi dưới dạng –log-path
  • env – [Tùy chọn] Ánh xạ các biến môi trường cho quy trình mới, mặc định là os. môi trường
webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
64 [ executable_path. str = 'chromedriver', cổng. int = 0, dịch vụ_args. Tùy chọn[Danh sách[str]] = Không, log_path. Tùy chọn[str] = Không, env. Tùy chọn[Ánh xạ[str, str]] = Không có ] → Không có

Tự khởi tạo. Xem help[type[self]] để có chữ ký chính xác

7. 20. Trình điều khiển web từ xa

Triển khai WebDriver

lớp
driver.current_url
65
driver.current_url
66

căn cứ.

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
77

Lớp cơ sở trừu tượng cho tất cả các kiểu con Webdriver. ABC cho phép đăng ký triển khai Webdriver tùy chỉnh để kiểm tra loại phiên bản sẽ thành công

lớp
driver.current_url
65_______778 [ command_executor='http. //127. 0. 0. 1. 4444', wish_capabilities=Không, browser_profile=Không, proxy=Không, keep_alive=True, file_detector=Không, tùy chọn. Liên minh [selenium. webdriver. phổ thông. tùy chọn. Tùy chọn cơ sở, Danh sách [selenium. webdriver. phổ thông. tùy chọn. BaseOptions]] = Không có ]

căn cứ.

Điều khiển trình duyệt bằng cách gửi lệnh đến máy chủ từ xa. Máy chủ này dự kiến ​​sẽ chạy giao thức dây WebDriver như được xác định tại https. //github. com/SeleniumHQ/selenium/wiki/JsonWireProtocol

Thuộc tính
  • session_id - Chuỗi ID của phiên trình duyệt được bắt đầu và kiểm soát bởi WebDriver này
  • các khả năng - Từ điển về các khả năng hiệu quả của phiên trình duyệt này do máy chủ từ xa trả về. Xem https. //github. com/SeleniumHQ/selenium/wiki/DesiredCapabilities
  • command_executor - remote_connection. Đối tượng RemoteConnection được sử dụng để thực thi lệnh
  • error_handler - trình xử lý lỗi. Đối tượng ErrorHandler dùng để xử lý lỗi
______364 [ command_executor='http. //127. 0. 0. 1. 4444', wish_capabilities=Không, browser_profile=Không, proxy=Không, keep_alive=True, file_detector=Không, tùy chọn. Liên minh [selenium. webdriver. phổ thông. tùy chọn. Tùy chọn cơ sở, Danh sách [selenium. webdriver. phổ thông. tùy chọn. BaseOptions]] = Không có ]

Tạo trình điều khiển mới sẽ ra lệnh bằng giao thức dây

lập luận
  • command_executor - Hoặc là một chuỗi đại diện cho URL của máy chủ từ xa hoặc một customremote_connection. Đối tượng kết nối từ xa. Mặc định là 'http. //127. 0. 0. 1. 4444/wd/trung tâm'
  • mong muốn_capabilities - Từ điển các khả năng yêu cầu khi bắt đầu phiên trình duyệt. tham số bắt buộc
  • browser_profile - Selenium. webdriver. firefox. firefox_profile. FirefoxProfile đối tượng. Chỉ được sử dụng nếu Firefox được yêu cầu. Không bắt buộc
  • proxy - Selenium. webdriver. phổ thông. Ủy quyền. đối tượng ủy nhiệm. Phiên trình duyệt sẽ được bắt đầu với cài đặt proxy nhất định, nếu có thể. Không bắt buộc
  • keep_alive - Có cấu hình remote_connection hay không. Kết nối từ xa để sử dụng HTTP duy trì. Mặc định là True
  • file_detector - Truyền đối tượng phát hiện tệp tùy chỉnh trong quá trình khởi tạo. Nếu Không, thì LocalFileDetector[] mặc định sẽ được sử dụng
  • tùy chọn - ví dụ về tùy chọn trình điều khiển. lớp tùy chọn
driver.current_url
72 [ cookie_dict ] → Không có

Thêm cookie vào phiên hiện tại của bạn

lập luận
  • cookie_dict. Một đối tượng từ điển, với các khóa bắt buộc - “tên” và “giá trị”; các khóa tùy chọn - “đường dẫn”, “miền”, “bảo mật”, “Chỉ http”, “hết hạn”, “sameSite”
Cách sử dụng. người lái xe. add_cookie[{‘tên’. 'foo', 'giá trị'. trình điều khiển 'thanh'}]. add_cookie[{‘tên’. 'foo', 'giá trị'. 'thanh', 'con đường'. '/'}] người lái xe. add_cookie[{‘tên’. 'foo', 'giá trị'. 'thanh', 'con đường'. '/', 'chắc chắn'. Đúng}] trình điều khiển. add_cookie[{‘tên’. 'foo', 'giá trị'. 'thanh', 'sameSite'. ‘Strict’}]
driver.current_url
73 [ thông tin xác thực. selen. webdriver. phổ thông. trình xác thực ảo. Thông tin xác thực ] → Không có

Tiêm thông tin xác thực vào trình xác thực

driver.current_url
74 [ tùy chọn. selen. webdriver. phổ thông. trình xác thực ảo. VirtualAuthenticatorOptions ] → Không có

Thêm trình xác thực ảo với các tùy chọn đã cho

driver.current_url
75 [] → Không có

Lùi một bước trong lịch sử trình duyệt

Cách sử dụng

from selenium.webdriver.common.keys import Keys
0

driver.current_url
76 []
driver.current_url
77 [] → None

Đóng cửa sổ hiện tại

Cách sử dụng

driver.close[]

______878 [ element_id. str ] → selen. webdriver. Xa xôi. phần tử web. Phần tử web

Tạo một phần tử web với phần tử_id được chỉ định

driver.current_url
79 [] → Không có

Xóa tất cả cookie trong phạm vi của phiên

Cách sử dụng

from selenium.webdriver.common.keys import Keys
2

driver.current_url
80 [ tên ] → Không có

Xóa một cookie với tên đã cho

Cách sử dụng

from selenium.webdriver.common.keys import Keys
3

______881 [ driver_command. str, thông số. dict = Không có ] → dict

Gửi một lệnh để được thực thi bởi một lệnh. LệnhExecutor

lập luận
  • driver_command. Tên của lệnh để thực thi dưới dạng một chuỗi
  • thông số. Một từ điển các tham số được đặt tên để gửi bằng lệnh
trả lại

Phản hồi JSON của lệnh được tải vào một đối tượng từ điển

______882 [ tập lệnh. str, *args ]

Thực thi JavaScript không đồng bộ trong cửa sổ/khung hiện tại

lập luận
  • kịch bản. JavaScript để thực thi
  • * lập luận. Mọi đối số có thể áp dụng cho JavaScript của bạn
Cách sử dụng

from selenium.webdriver.common.keys import Keys
4

driver.current_url
83 [ script, *args ]

Thực thi đồng bộ JavaScript trong cửa sổ/khung hiện tại

lập luận
  • kịch bản. JavaScript để thực thi
  • * lập luận. Mọi đối số có thể áp dụng cho JavaScript của bạn
Cách sử dụng

from selenium.webdriver.common.keys import Keys
5

driver.current_url
84 [ file_detector_class, *args, **kwargs ]

Ghi đè trình phát hiện tệp hiện tại [nếu cần] trong ngữ cảnh hạn chế. Đảm bảo trình phát hiện tệp gốc được đặt sau đó

Ví dụ

với webdriver. file_detector_context[FileDetector vô dụng]. đầu vào nào đó. send_keys[‘/etc/hosts’]Args
  • file_detector_class - Lớp của trình phát hiện tệp mong muốn. Nếu lớp khác với file_detector hiện tại, thì lớp này được khởi tạo bằng args và kwargs và được sử dụng làm trình phát hiện tệp trong suốt thời gian của trình quản lý ngữ cảnh
  • args - Các đối số tùy chọn được chuyển đến lớp trình phát hiện tệp trong quá trình khởi tạo
  • kwargs - Đối số từ khóa, được truyền giống như đối số
driver.current_url
85 [ by='id', giá trị. Tùy chọn[str] = Không có ] → selen. webdriver. Xa xôi. phần tử web. Phần tử web

Tìm phần tử đã cho a Bằng chiến lược và bộ định vị

Cách sử dụng

from selenium.webdriver.common.keys import Keys
6

loại trả lại

driver.current_url
86 [ by='id', giá trị. Tùy chọn[str] = Không có ] → Danh sách[selenium. webdriver. Xa xôi. phần tử web. Phần tử web]

Tìm các phần tử đã cho a Theo chiến lược và định vị

Cách sử dụng

from selenium.webdriver.common.keys import Keys
7

loại trả lại

danh sách WebElement

driver.current_url
87 [] → Không có

Đi một bước về phía trước trong lịch sử trình duyệt

Cách sử dụng

from selenium.webdriver.common.keys import Keys
8

driver.current_url
88 [] → Không có

Gọi thao tác 'toàn màn hình' dành riêng cho trình quản lý cửa sổ

______889 [ url. str ] → Không có

Tải một trang web trong phiên trình duyệt hiện tại

driver.current_url
90 [ tên ] → Tùy chọn[Dict[

Nhận một cookie duy nhất theo tên. Trả về cookie nếu tìm thấy, Không có nếu không

Cách sử dụng

from selenium.webdriver.common.keys import Keys
9

driver.current_url
91 [] → Danh sách[dict]

Trả về một bộ từ điển, tương ứng với cookie hiển thị trong phiên hiện tại

Cách sử dụng

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
0

driver.current_url
92 [] → Danh sách[selenium. webdriver. phổ thông. trình xác thực ảo. Thông tin xác thực]

Trả về danh sách thông tin đăng nhập thuộc sở hữu của trình xác thực

driver.current_url
93 [ log_type ]

Nhận nhật ký cho một loại nhật ký nhất định

lập luận
  • log_type. loại nhật ký sẽ được trả lại
Cách sử dụng

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
1

driver.current_url
94 [] → Danh sách[str]
driver.current_url
95 . Cách sử dụng. ] → strGets the screenshot of the current window as a base64 encoded stringwhich is useful in embedded images in HTML.Usage:

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
2

driver.current_url
96 [ tên tệp ] → boolLưu ảnh chụp màn hình của . Trả về Sai nếu có bất kỳ IOError nào, ngược lại trả về Đúng. Sử dụng đường dẫn đầy đủ trong tên tệp của bạn. lập luận.
  • tên tập tin. Đường dẫn đầy đủ mà bạn muốn lưu ảnh chụp màn hình của mình vào. Điều này sẽ kết thúc với một. phần mở rộng png
Cách sử dụng

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
3

driver.current_url
97 [] → byte

Lấy ảnh chụp màn hình của cửa sổ hiện tại dưới dạng dữ liệu nhị phân

Cách sử dụng

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
4

driver.current_url
98 [ windowHandle='current' ]

Lấy vị trí x, y của cửa sổ hiện tại

Cách sử dụng

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
5

driver.current_url
99 [] → lệnh

Nhận tọa độ x, y của cửa sổ cũng như chiều cao và chiều rộng của cửa sổ hiện tại

Cách sử dụng

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
6

______900 [ windowHandle. str = 'hiện tại' ] → dict

Lấy chiều rộng và chiều cao của cửa sổ hiện tại

Cách sử dụng

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
7

______901 [ time_to_wait. float ] → Không đặt thời gian chờ cố định để chờ hoàn toàn một phần tử được tìm thấy hoặc một lệnh hoàn thành. Phương thức này chỉ cần được gọi một lần trong mỗi phiên. Để đặt thời gian chờ cho các lệnh gọi đến exec_async_script, hãy xem set_script_timeout. lập luận.
  • time_to_wait. Lượng thời gian chờ đợi [tính bằng giây]
Cách sử dụng

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
8

driver.close[]
02 [] → Không có

Tối đa hóa cửa sổ hiện tại mà webdriver đang sử dụng

driver.close[]
03 [] → Không có

Gọi thao tác 'thu nhỏ' dành riêng cho trình quản lý cửa sổ

______904 [ tập lệnh. str, script_key=None ] → Selenium. webdriver. Xa xôi. script_key. ScriptKey

Lưu trữ các tập lệnh javascript phổ biến sẽ được thực thi sau này bằng một ID có thể băm duy nhất

______905 [ print_options. Tùy chọn [selenium. webdriver. phổ thông. print_page_options. PrintOptions] = Không có ] → str

Đưa PDF của trang hiện tại. Trình điều khiển cố gắng hết sức để trả về tệp PDF dựa trên các tham số được cung cấp

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
89 [] → Không có

Thoát khỏi trình điều khiển và đóng mọi cửa sổ liên quan

Cách sử dụng

from selenium.common.exceptions import [TheNameOfTheExceptionClass]
9

driver.close[]
07 [] → Không có

Làm mới trang hiện tại

Cách sử dụng

driver.current_url
0

driver.close[]
08 [] → Không có

Xóa tất cả thông tin đăng nhập khỏi trình xác thực

______909 [ credential_id. Union[str, bytearray] ] → Không có

Xóa thông tin xác thực khỏi trình xác thực

driver.close[]
10 [] → Không có

Xóa trình xác thực ảo đã thêm trước đó. Trình xác thực không còn hiệu lực sau khi xóa, vì vậy không có phương thức nào có thể được gọi

driver.close[]
11 [ tên tệp ] → boolLưu ảnh chụp màn hình của . Trả về Sai nếu có bất kỳ IOError nào, ngược lại trả về Đúng. Sử dụng đường dẫn đầy đủ trong tên tệp của bạn. lập luận.
  • tên tập tin. Đường dẫn đầy đủ mà bạn muốn lưu ảnh chụp màn hình của mình vào. Điều này sẽ kết thúc với một. phần mở rộng png
Cách sử dụng

driver.current_url
1

______912 [ time_to_wait. float ] → Không cóĐặt khoảng thời gian chờ tải trang hoàn tất trước khi đưa ra lỗi. lập luận.
  • time_to_wait. Lượng thời gian chờ đợi
Cách sử dụng

driver.current_url
2

______913 [ time_to_wait. float ] → Không cóĐặt khoảng thời gian mà tập lệnh sẽ đợi trong lệnh gọi anexecute_async_script trước khi đưa ra lỗi. lập luận.
  • time_to_wait. Lượng thời gian chờ đợi [tính bằng giây]
Cách sử dụng

driver.current_url
3

____914 [ đã xác minh. bool ] → Không có

Đặt xem trình xác thực sẽ mô phỏng thành công hay thất bại khi xác minh người dùng. xác minh. Đúng nếu trình xác thực sẽ vượt qua xác minh người dùng, Sai nếu không

______915 [ x, y, windowHandle. str = 'hiện tại' ] → dict

Đặt vị trí x, y của cửa sổ hiện tại. [cửa sổ. chuyển tới]

lập luận
  • x. tọa độ x tính bằng pixel để đặt vị trí cửa sổ
  • y. tọa độ y tính bằng pixel để đặt vị trí cửa sổ
Cách sử dụng

driver.current_url
4

driver.close[]
16 [ x=Không, y=Không, chiều rộng=Không, chiều cao=Không ] → dict

Đặt tọa độ x, y của cửa sổ cũng như chiều cao và chiều rộng của cửa sổ hiện tại. Phương pháp này chỉ được hỗ trợ cho các trình duyệt tương thích với W3C;

Cách sử dụng

driver.current_url
5

______917 [ chiều rộng, chiều cao, tay cầm cửa sổ. str = 'hiện tại' ] → Không có

Đặt chiều rộng và chiều cao của cửa sổ hiện tại. [cửa sổ. thay đổi kích thướcTo]

lập luận
  • chiều rộng. chiều rộng tính bằng pixel để đặt cửa sổ thành
  • Chiều cao. chiều cao tính bằng pixel để đặt cửa sổ thành
Cách sử dụng

driver.current_url
6

______918 []

Được gọi trước khi bắt đầu một phiên làm việc mới. Phương thức này có thể bị ghi đè để xác định hành vi khởi động tùy chỉnh

______919 [ khả năng. dict, browser_profile=None ] → Không có

Tạo một phiên mới với các khả năng mong muốn

lập luận
  • khả năng - một lệnh khả năng để bắt đầu phiên với
  • browser_profile - Selenium. webdriver. firefox. firefox_profile. FirefoxProfile đối tượng. Chỉ được sử dụng nếu Firefox được yêu cầu
______920 []

Được gọi sau khi thực hiện lệnh thoát. Phương pháp này có thể bị ghi đè để xác định hành vi tắt máy tùy chỉnh

______921 [ script_key. selen. webdriver. Xa xôi. script_key. ScriptKey ] → Không có

Xóa tập lệnh được ghim khỏi bộ lưu trữ

driver.close[]
22

Trả về một Đối tượng ApplicationCache để tương tác với bộ đệm của ứng dụng trình duyệt

driver.close[]
23

trả về các khả năng hiện tại của trình điều khiển đang được sử dụng

driver.close[]
24

Lấy URL của trang hiện tại

Cách sử dụng

________số 8

driver.close[]
25

Trả về tay cầm của cửa sổ hiện tại

Cách sử dụng

driver.current_url
8

driver.close[]
26

trả về các khả năng mong muốn hiện tại của trình điều khiển đang được sử dụng

driver.close[]
27
driver.close[]
28

Nhận danh sách các loại nhật ký có sẵn. Điều này chỉ hoạt động với các trình duyệt tuân thủ w3c

Cách sử dụng

driver.current_url
9

driver.close[]
29
driver.close[]
30

Trả về tên của trình duyệt cơ bản cho trường hợp này

Cách sử dụng

driver.close[]
0

driver.close[]
31

Lấy hướng hiện tại của thiết bị

Cách sử dụng

driver.close[]
1

driver.close[]
32

Lấy nguồn của trang hiện tại

Cách sử dụng

driver.close[]
2

driver.close[]
33Trả về
  • Chuyển sang. một đối tượng chứa tất cả các tùy chọn để chuyển tiêu điểm thành
Cách sử dụng

driver.close[]
3

driver.close[]
34

Nhận tất cả thời gian chờ đã được đặt trên phiên hiện tại

Cách sử dụng

người lái xe. hết giờ

loại trả lại

Hết giờ

driver.close[]
35

Trả về tiêu đề của trang hiện tại

Cách sử dụng

driver.close[]
4

driver.close[]
36

Trả về id của trình xác thực ảo

driver.close[]
37

Trả về tay cầm của tất cả các cửa sổ trong phiên hiện tại

Cách sử dụng

driver.close[]
5

driver.current_url
65_______939 [ tùy chọn. Danh sách [selenium. webdriver. phổ thông. tùy chọn. BaseOptions] ] → Dict[KT, VT]
driver.current_url
65
driver.close[]
41 [ khả năng, ]
driver.current_url
65
driver.close[]
43[]

7. 21. Trình điều khiển web từ xa WebElement

lớp
driver.close[]
44____945

căn cứ.

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
77

Lớp cơ sở trừu tượng cho WebElement. ABC sẽ cho phép các loại tùy chỉnh được đăng ký dưới dạng WebElement để vượt qua kiểm tra loại

lớp
driver.close[]
44
driver.close[]
48 [ cha mẹ, id_ ]

căn cứ.

Đại diện cho một phần tử DOM

Nói chung, tất cả các thao tác thú vị tương tác với tài liệu sẽ được thực hiện thông qua giao diện này

Tất cả các cuộc gọi phương thức sẽ thực hiện kiểm tra độ mới để đảm bảo rằng tham chiếu phần tử vẫn hợp lệ. Về cơ bản, điều này xác định xem phần tử có còn được gắn vào DOM hay không. Nếu thử nghiệm này không thành công, thì một

driver.close[]
50 sẽ bị ném và tất cả các cuộc gọi trong tương lai tới phiên bản này sẽ không thành công

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
64 [ cha mẹ, id_ ]

Tự khởi tạo. Xem help[type[self]] để có chữ ký chính xác

driver.close[]
52 [] → Không có

Xóa văn bản nếu đó là thành phần nhập văn bản

webdriver.Firefox
webdriver.FirefoxProfile
webdriver.Chrome
webdriver.ChromeOptions
webdriver.Ie
webdriver.Opera
webdriver.PhantomJS
webdriver.Remote
webdriver.DesiredCapabilities
webdriver.ActionChains
webdriver.TouchActions
webdriver.Proxy
79 [] → Không có

Nhấp vào phần tử

driver.current_url
85 [ by='id', value=None ] → selenium.webdriver.remote.webelement.WebElement

Tìm phần tử đã cho a Bằng chiến lược và bộ định vị

Cách sử dụng

driver.close[]
6

loại trả lại

driver.current_url
86 [ by='id', value=None ] → list[WebElement]

Tìm các phần tử đã cho a Theo chiến lược và định vị

Cách sử dụng

driver.close[]
7

loại trả lại

danh sách WebElement

driver.close[]
56 [ tên ] → str

Nhận thuộc tính hoặc thuộc tính đã cho của phần tử

Phương thức này trước tiên sẽ cố gắng trả về giá trị của thuộc tính có tên đã cho. Nếu một thuộc tính có tên đó không tồn tại, nó sẽ trả về giá trị của thuộc tính có cùng tên. Nếu không có thuộc tính nào với tên đó, thì trả về

driver.close[]
57

Các giá trị được coi là trung thực, tương đương với “true” hoặc “false”, được trả về dưới dạng boolean. Tất cả các giá trị khác không phải ____957 được trả về dưới dạng chuỗi. Đối với các thuộc tính hoặc thuộc tính không tồn tại,

driver.close[]
57 được trả về

Để có được giá trị chính xác của thuộc tính hoặc thuộc tính, hãy sử dụng các phương pháp

driver.close[]
60 hoặc
driver.close[]
61 tương ứng

lập luận
  • name - Tên của thuộc tính/thuộc tính cần truy xuất

Ví dụ

driver.close[]
8

driver.close[]
62 [ tên ] → str

Lấy thuộc tính đã cho của phần tử. Không giống như

driver.close[]
63, phương thức này chỉ trả về các thuộc tính được khai báo trong phần đánh dấu HTML của phần tử

lập luận
  • name - Tên của thuộc tính cần truy xuất
Cách sử dụng

driver.close[]
9

______964 [ tên ] → str. bool. WebYếu tố. lệnh

Lấy thuộc tính đã cho của phần tử

lập luận
  • name - Tên của tài sản để lấy
Cách sử dụng

from selenium.webdriver.common.keys import Keys
60

driver.close[]
65 [] → bool

Liệu phần tử có hiển thị với người dùng hay không

driver.close[]
66 [] → bool

Trả về xem phần tử có được bật hay không

driver.close[]
67 [] → bool

Trả về phần tử có được chọn hay không

Có thể được sử dụng để kiểm tra xem hộp kiểm hoặc nút radio có được chọn không

driver.close[]
68 [ tên tệp ] → boolLưu ảnh chụp màn hình của . Trả về Sai nếu có bất kỳ IOError nào, ngược lại trả về Đúng. Sử dụng đường dẫn đầy đủ trong tên tệp của bạn. lập luận.
  • tên tập tin. Đường dẫn đầy đủ mà bạn muốn lưu ảnh chụp màn hình của mình vào. Điều này sẽ kết thúc với một. phần mở rộng png
Cách sử dụng

from selenium.webdriver.common.keys import Keys
61

______398 [ *giá trị ] → Không có

Chủ Đề