Home > Blockchain >  How to verify if a button from a page is really disabled in a chromedriver window on Python? Seleniu
How to verify if a button from a page is really disabled in a chromedriver window on Python? Seleniu

Time:01-22

I'm trying to automate a process on problem_preview1

But, if I click twice the same wallet icon (one to close the aside element, and other to open it again), they get enabled:

problem_preview2

So, I would like to learn how could I improve the code above to make sure it really detects when all of those 4 buttons (Metamask and the other 3) are enabled.

CodePudding user response:

Ok, here it is: First: The locators are not relative enough, so I took the freedom to refactor them. Second: MetaMask is not a button as per DOM DOM Snapshot but the rest are. However, instead of relying on the buttons, I tried to rely on the li (which is common for all), and checking whether they are enabled or not. Third: If you are trying to find if all the 4 elements are enabled, then you must use find_elements instead of find_element and then loop through the elements to check if each is enabled. Please check if this works for you:

driver.get('https://opensea.io/') #go to the opensea main page.
WebDriverWait(driver, 3).until(EC.element_to_be_clickable((By.XPATH, "//*[@title='Wallet']"))) #wait for the wallet button to be enabled for clicking
wallet_button = driver.find_element(By.XPATH, "//*[@title='Wallet']")
wallet_button.click() #click that wallet button
wallet_options = driver.find_elements(By.XPATH, "//*[@data-testid='WalletSidebar--body']//li")
for wallet in wallet_options:
    if wallet.is_enabled():
        print(f"{wallet.text} is enabled")
    else:
        print(f"f{wallet.text} is not enabled")
  •  Tags:  
  • Related