-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestd.py
27 lines (19 loc) · 1.08 KB
/
testd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from selenium import webdriver
from selenium.webdriver.remote.webdriver import WebDriver
def add_credentials_moz(driver, target, username, password):
driver.execute("SET_CONTEXT", {"context": "chrome"})
driver.execute_script("""
let [target, username, password] = [...arguments];
let WebRequest = Cu.import('resource://gre/modules/WebRequest.jsm', {});
WebRequest.onAuthRequired.addListener(function listener(){
WebRequest.onAuthRequired.removeListener(listener);
return Promise.resolve({authCredentials: {username: username, password: password}});
}, {urls: new MatchPatternSet([target])}, ['blocking']);
""", target, username, password)
driver.execute("SET_CONTEXT", {"context": "content"})
WebDriver.add_credentials_moz = add_credentials_moz
driver = webdriver.Firefox()
driver.add_credentials_moz("https://httpbin.org/*", username="user", password="passwd")
driver.get("https://httpbin.org/")
driver.find_element_by_css_selector("[href='/basic-auth/user/passwd']")\
.click()