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_url29
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 webdriver10 [ 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 webdriver13 [ 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 webdriver16 [ 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 webdriver19 [ 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.Proxy02 [ 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.Proxy05 [ 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.Proxy08 [ 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.Proxy11 [ 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.Proxy14 [ 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.Proxy17 [ 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.Proxy20 [ 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.Proxy23 [ 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.Proxy26 [ 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.Proxy29 [ 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.Proxy32 [ 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
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.Proxy35 [ 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.Proxy38 [ 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.Proxy41 [ 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 Keys6ngoạ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.Proxy44 [ 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.Proxy47 [ 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.Proxy50 [ 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.Proxy53 [ 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
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.Proxy56 [ 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.Proxy59 [ 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.Proxy62 [ 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.Proxy66 [ 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.Proxy69 [ 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.Proxy72 [ 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.Proxy73
Ngoại lệ webdriver cơ sở
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ạngwebdriver.Firefox webdriver.FirefoxProfile webdriver.Chrome webdriver.ChromeOptions webdriver.Ie webdriver.Opera webdriver.PhantomJS webdriver.Remote webdriver.DesiredCapabilities webdriver.ActionChains webdriver.TouchActions webdriver.Proxy75
webdriver.Firefox webdriver.FirefoxProfile webdriver.Chrome webdriver.ChromeOptions webdriver.Ie webdriver.Opera webdriver.PhantomJS webdriver.Remote webdriver.DesiredCapabilities webdriver.ActionChains webdriver.TouchActions webdriver.Proxy76 [ 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.Proxy77
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 đợiActionChains 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.Proxy64 [ 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.Proxy79 [ 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.Proxy80 [ 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.Proxy81 [ 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.Proxy82 [ 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.Proxy83 [ 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.Proxy84 [ 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.Proxy85 [ 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 webdriver1
webdriver.Firefox webdriver.FirefoxProfile webdriver.Chrome webdriver.ChromeOptions webdriver.Ie webdriver.Opera webdriver.PhantomJS webdriver.Remote webdriver.DesiredCapabilities webdriver.ActionChains webdriver.TouchActions webdriver.Proxy86 [ 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 webdriver1
webdriver.Firefox webdriver.FirefoxProfile webdriver.Chrome webdriver.ChromeOptions webdriver.Ie webdriver.Opera webdriver.PhantomJS webdriver.Remote webdriver.DesiredCapabilities webdriver.ActionChains webdriver.TouchActions webdriver.Proxy87 [ 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
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.Proxy89 [ 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.Proxy90 [ 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.Proxy92 [ 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
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
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.Proxy96 [ 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
webdriver.Firefox webdriver.FirefoxProfile webdriver.Chrome webdriver.ChromeOptions webdriver.Ie webdriver.Opera webdriver.PhantomJS webdriver.Remote webdriver.DesiredCapabilities webdriver.ActionChains webdriver.TouchActions webdriver.Proxy97 [ . 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.Proxy98 [ *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.Proxy99 [ 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ạngfrom selenium.webdriver.common.keys import Keys00
from selenium.webdriver.common.keys import Keys01 [ 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.Proxy77
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.Proxy1
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.Proxy64 [ 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
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 Keys07
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ớpfrom selenium.webdriver.common.keys import Keys08
from selenium.webdriver.common.keys import Keys09
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.Proxy77
Bộ mã khóa đặc biệt
from selenium.webdriver.common.keys import Keys11 = '\ue025'
from selenium.webdriver.common.keys import Keys12 = '\ue00a'
from selenium.webdriver.common.keys import Keys13 = '\ue015'
from selenium.webdriver.common.keys import Keys14 = '\ue012'
from selenium.webdriver.common.keys import Keys15 = '\ue014'
from selenium.webdriver.common.keys import Keys16 = '\ue013'
from selenium.webdriver.common.keys import Keys17 = '\ue003'
from selenium.webdriver.common.keys import Keys18 = '\ue003'
from selenium.webdriver.common.keys import Keys19 =
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 ________ 577că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.Proxy77
Tập hợp các chiến lược định vị được hỗ trợ
from selenium.webdriver.common.keys import Keys79 = 'tên lớp'_______580 = 'bộ chọn css'
from selenium.webdriver.common.keys import Keys81 = 'id'
from selenium.webdriver.common.keys import Keys82 = 'văn bản liên kết'
from selenium.webdriver.common.keys import Keys83 = 'tên'
from selenium.webdriver.common.keys import Keys84 = 'văn bản liên kết một phần'
from selenium.webdriver.common.keys import Keys85 = 'tên thẻ'
from selenium.webdriver.common.keys import Keys86 = '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ớpfrom selenium.webdriver.common.keys import Keys87____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.Proxy77
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.Proxy2
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 Keys90 = {'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 Keys93 = {'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ớpfrom 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.Proxy77
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.Proxy64 [ 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 = ''______ 709Trả 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ớpfrom 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.Proxy77
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. classmethodfrom 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.Proxy77
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
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ớpfrom 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
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ạngfrom 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.Proxy77
webdriver.Firefox webdriver.FirefoxProfile webdriver.Chrome webdriver.ChromeOptions webdriver.Ie webdriver.Opera webdriver.PhantomJS webdriver.Remote webdriver.DesiredCapabilities webdriver.ActionChains webdriver.TouchActions webdriver.Proxy64 [ 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ớpfrom 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.Proxy64 [ 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_CONTENTVí 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.Proxy3
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.Proxy4
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
webdriver.Firefox webdriver.FirefoxProfile webdriver.Chrome webdriver.ChromeOptions webdriver.Ie webdriver.Opera webdriver.PhantomJS webdriver.Remote webdriver.DesiredCapabilities webdriver.ActionChains webdriver.TouchActions webdriver.Proxy5
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ụngwebdriver.Firefox webdriver.FirefoxProfile webdriver.Chrome webdriver.ChromeOptions webdriver.Ie webdriver.Opera webdriver.PhantomJS webdriver.Remote webdriver.DesiredCapabilities webdriver.ActionChains webdriver.TouchActions webdriver.Proxy6
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ụngwebdriver.Firefox webdriver.FirefoxProfile webdriver.Chrome webdriver.ChromeOptions webdriver.Ie webdriver.Opera webdriver.PhantomJS webdriver.Remote webdriver.DesiredCapabilities webdriver.ActionChains webdriver.TouchActions webdriver.Proxy7
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
webdriver.Firefox webdriver.FirefoxProfile webdriver.Chrome webdriver.ChromeOptions webdriver.Ie webdriver.Opera webdriver.PhantomJS webdriver.Remote webdriver.DesiredCapabilities webdriver.ActionChains webdriver.TouchActions webdriver.Proxy8
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ụngwebdriver.Firefox webdriver.FirefoxProfile webdriver.Chrome webdriver.ChromeOptions webdriver.Ie webdriver.Opera webdriver.PhantomJS webdriver.Remote webdriver.DesiredCapabilities webdriver.ActionChains webdriver.TouchActions webdriver.Proxy9
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ớpfrom 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.Proxy77______364 []
Tự khởi tạo. Xem help[type[self]] để có chữ ký chính xác
driver.current_url00 [] → dictclass
from selenium.common.exceptions import [TheNameOfTheExceptionClass]96
driver.current_url02
căn cứ.
driver.current_url03______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 đầudriver.current_url06 [ name. str, giá trị. Liên minh[str, int, bool] ]
Đặt tùy chọn
driver.current_url00 [] → lệnh
Nguyên soái các tùy chọn Firefox thành moz. đối tượng firefoxOptions
driver.current_url08 = 'moz. firefoxOptions'____809
Trả về phiên bản FirefoxBinary
driver.current_url10Trả lại. Vị trí nhị phân.
driver.current_url11
Trả lại các khả năng tối thiểu cần thiết như một từ điển
driver.current_url12Trả 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_url14Trả lại. Hồ sơ Firefox để sử dụng
7. 14. Hồ sơ Firefox WebDriver
ngoại lệdriver.current_url15
driver.current_url16
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.Proxy73
Ngoại lệ cho các tệp kê khai bổ trợ không được định dạng tốt
lớpdriver.current_url15_______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.Proxy77
webdriver.Firefox webdriver.FirefoxProfile webdriver.Chrome webdriver.ChromeOptions webdriver.Ie webdriver.Opera webdriver.PhantomJS webdriver.Remote webdriver.DesiredCapabilities webdriver.ActionChains webdriver.TouchActions webdriver.Proxy64 [ 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_url22 [ extension='webdriver. xpi' ]
driver.current_url06 [ khóa, giá trị ]
đặt tùy chọn mà chúng tôi muốn trong hồ sơ
driver.current_url24 []
driver.current_url25 = 'WEBDRIVER_ANONYMOUS_PROFILE'
driver.current_url26 = Không
driver.current_url27
driver.current_url28
driver.current_url29
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_url30
Nhận thư mục hồ sơ hiện đang được sử dụng
driver.current_url31
Nhận cổng mà WebDriver đang hoạt động
7. 15. Firefox WebDriver nhị phân
lớpdriver.current_url32
driver.current_url33 [ 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.Proxy77
webdriver.Firefox webdriver.FirefoxProfile webdriver.Chrome webdriver.ChromeOptions webdriver.Ie webdriver.Opera webdriver.PhantomJS webdriver.Remote webdriver.DesiredCapabilities webdriver.ActionChains webdriver.TouchActions webdriver.Proxy64 [ 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_url36 [ *args ]
driver.current_url37 []
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_url38 [ 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_url39 [ 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_url40 = 'x_ignore_nofocus. Vì thế'
7. 16. Kết nối tiện ích mở rộng Firefox WebDriver
ngoại lệdriver.current_url41____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.Proxy73
Đã 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ớpdriver.current_url41
driver.current_url45 [ 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.Proxy64 [ 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_url48 []
Kết nối với tiện ích mở rộng và truy xuất id phiên
phương thức lớpdriver.current_url49 []
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ớpfrom 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ớpdriver.current_url52_______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_url54
Đ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.Proxy64 [ 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ớpdriver.current_url56
driver.current_url02
căn cứ.
driver.current_url58______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 đầudriver.current_url11
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ớpdriver.current_url61
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_url63
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.Proxy64 [ 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ớpdriver.current_url65
driver.current_url66
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.Proxy77
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ớpdriver.current_url65_______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
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_url72 [ 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”
driver.current_url73 [ 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_url74 [ 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_url75 [] → Không có
Lùi một bước trong lịch sử trình duyệt
Cách sử dụngfrom selenium.webdriver.common.keys import Keys0
driver.current_url76 []
driver.current_url77 [] → None
Đóng cửa sổ hiện tại
Cách sử dụngdriver.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_url79 [] → Không có
Xóa tất cả cookie trong phạm vi của phiên
Cách sử dụngfrom selenium.webdriver.common.keys import Keys2
driver.current_url80 [ tên ] → Không có
Xóa một cookie với tên đã cho
Cách sử dụngfrom selenium.webdriver.common.keys import Keys3______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
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
from selenium.webdriver.common.keys import Keys4
driver.current_url83 [ 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
from selenium.webdriver.common.keys import Keys5
driver.current_url84 [ 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_url85 [ 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ụngfrom selenium.webdriver.common.keys import Keys6loại trả lại
driver.current_url86 [ 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ụngfrom selenium.webdriver.common.keys import Keys7loại trả lại
danh sách WebElement
driver.current_url87 [] → 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ụngfrom selenium.webdriver.common.keys import Keys8
driver.current_url88 [] → 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_url90 [ 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ụngfrom selenium.webdriver.common.keys import Keys9
driver.current_url91 [] → 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ụngfrom selenium.common.exceptions import [TheNameOfTheExceptionClass]0
driver.current_url92 [] → 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_url93 [ 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
from selenium.common.exceptions import [TheNameOfTheExceptionClass]1
driver.current_url94 [] → Danh sách[str]
driver.current_url95 . 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_url96 [ 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
from selenium.common.exceptions import [TheNameOfTheExceptionClass]3
driver.current_url97 [] → 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ụngfrom selenium.common.exceptions import [TheNameOfTheExceptionClass]4
driver.current_url98 [ windowHandle='current' ] →
Lấy vị trí x, y của cửa sổ hiện tại
Cách sử dụngfrom selenium.common.exceptions import [TheNameOfTheExceptionClass]5
driver.current_url99 [] → 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ụngfrom 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ụngfrom 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]
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. ScriptKeyLư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ụngfrom 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ụngdriver.current_url0
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
driver.current_url1______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
driver.current_url2______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]
driver.current_url3____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ổ
driver.current_url4
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ụngdriver.current_url5______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
driver.current_url6______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
Đượ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ụngdriver.current_url8
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ụngdriver.current_url9
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ụngdriver.close[]0
driver.close[]31
Lấy hướng hiện tại của thiết bị
Cách sử dụngdriver.close[]1
driver.close[]32
Lấy nguồn của trang hiện tại
Cách sử dụngdriver.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
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ụngngười lái xe. hết giờ
loại trả lạiHết giờ
driver.close[]35
Trả về tiêu đề của trang hiện tại
Cách sử dụngdriver.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ụngdriver.close[]5
driver.current_url65_______939 [ tùy chọn. Danh sách [selenium. webdriver. phổ thông. tùy chọn. BaseOptions] ] → Dict[KT, VT]
driver.current_url65
driver.close[]41 [ khả năng, ]
driver.current_url65
driver.close[]43[]
7. 21. Trình điều khiển web từ xa WebElement
lớpdriver.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.Proxy77
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ớpdriver.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.Proxy64 [ 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.Proxy79 [] → Không có
Nhấp vào phần tử
driver.current_url85 [ 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ụngdriver.close[]6loại trả lại
driver.current_url86 [ 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ụngdriver.close[]7loạ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 ứnglậ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
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
from selenium.webdriver.common.keys import Keys60
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
from selenium.webdriver.common.keys import Keys61______398 [ *giá trị ] → Không có