I have a website that I want to log into using Python's Selenium. But I can't get an xpath or something like that.
So, how do I log in? I already tried:
DRIVER.find_element_by_tag_name('body').send_keys('test')
and
actions = ActionChains(DRIVER)
actions.send_keys('test')
actions.perform()
but both are not working.
CodePudding user response:
This is an HTTP authentication not a login web page.
Use something like this:
from selenium import webdriver
username = 'myusername'
password = 'mypassword'
url = f'http://{username}:{password}@webtrash.musictunnel8080.de/'
options = webdriver.ChromeOptions()
options.add_argument('--disable-blink-features="BlockCredentialedSubresources"')
driver = webdriver.Chrome(options=options)
driver.get(url)
Update
Use requests
package:
import requests
from requests.auth import HTTPBasicAuth
username = 'myusername'
password = 'mypassword'
url = 'http://webtrash.musictunnel8080.de/'
auth = HTTPBasicAuth(username, password)
r = requests.get(url, auth=auth)