Im trying to automatically sign in the Phantom wallet after its extension installed on webdriver and signing page is opened but no matter how i try to find a button element, selenium throws an error. I even added webdriver wait function but it doesnt help.
Here is my code:
import os
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
import eden_ab.constants as const
from selenium import webdriver
os.environ['PATH'] = const.DRIVER_PATH #valid driver path
#adding Phantom extension and launching driver
chop = webdriver.ChromeOptions()
chop.add_extension("res/Phantom 0.14.1.0.crx")
driver = webdriver.Chrome(options=chop)
driver.implicitly_wait(5)
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CLASS_NAME, 'sc-bdvvtL ljDDId'))) #here is where the error occures after wait timeout
phantom_signin = driver.find_element('sc-bdvvtL ljDDId')
phantom_signin.click
This code throws following error:
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CLASS_NAME, 'sc-bdvvtL ljDDId')))
This is the grey button im trying to click on extension onboard page:
chrome-extension://bfnaelmomeimhlpmgjnjophhpkkoljpa/onboarding.html
UPDATED: it throws this error if i remove webdriver wait
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: invalid locator
CodePudding user response:
sc-bdvvtL ljDDId actually contains 2 class names.
To match this element you can ever use this css_selector
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, '.sc-bdvvtL.ljDDId')))
or to put a dot . instead of the space there still using the By.CLASS_NAME:
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CLASS_NAME, 'sc-bdvvtL.ljDDId')))
CodePudding user response:
The error is self-explanatory:
find_element does not work like this:
phantom_signin = driver.find_element('sc-bdvvtL ljDDId')
instead it should be:
phantom_signin = driver.find_element_by_css_selector('.sc-bdvvtL.ljDDId')
or
phantom_signin = driver.find_element(By.CSS_SELECTOR, ".sc-bdvvtL.ljDDId")
A class having name like this sc-bdvvtL ljDDId isn't supported by CLASS_NAME in Selenium Python bindings cause we do not have support for spaces, you can remove space and put a . to make a CSS selector.
