import re
from datetime import datetime as dt
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
import time
opt = webdriver.ChromeOptions()
profile_path = r'C:\\Users\\*UserName*\\AppData\\Local\\Google\\Chrome\\UserData'
opt.add_argument('--user-data-dir={}'.format(profile_path)) # profile path
opt.add_argument('--profile-directory={}'.format('DEFAULT')) #profile name
opt.add_argument('--log-level=3')
EXTENSION_PATH = 'MM/metamask.crx'
opt.add_extension(EXTENSION_PATH)
driver = webdriver.Chrome('Driver/chromedriver.exe', chrome_options=opt)
global_dynamicUrl = "site"
driver.get(global_dynamicUrl)
driver.find_element_by_class_name("MuiButton-label").click()
driver.find_element_by_xpath("/html/body/div[3]/div[3]/nav/button[1]/span[1]").click()
password="**********"
driver.implicitly_wait(20)
Gives the error
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="password"]"}
I tried numerous other paths:
#Tried by xpath:
#//*[@id="password"]
#//*[@id="app-content"]/div/div[3]/div/div/form/div/div
#('//input')
#'/*[@id="password"]' -> AttributeError: 'str' object has no attribute 'send_keys'
#'/html/body/div[1]/div/div[3]/div/div/form/div/div/input'
#Tried by.Name:
#(By.NAME,('Password'))
# Tried by selector
# #password
#'//div[contains(@class, "metamask tw-flex tw-items-center tw-p-3")]'
# Tried by CLASS_NAME
#('MuiInputBase-input MuiInput-input')
I followed this at the beginning: automated dapps scrapping with selenium and metamask, from a dev site, and didn’t work either.