Selenium is unable to identify a clickable button in this scenario

<html lang="en">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Unique Phantom Wallet Title</title>
  <style>
    @font-face {
      font-family: Circular;
      font-style: normal;
      font-weight: 700;
      src: url(/Circular-Bold.ab51009b.woff) format("woff")
    }
    
    @font-face {
      font-family: Inter;
      font-style: normal;
      font-weight: 400;
      src: url(/Inter-Regular.f744dc98.woff) format("woff")
    }
   - additional fonts here -
   // shortened for brevity

  <link rel="stylesheet" href="/onboarding.6e49cdaa.css">

</head>

<body> <noscript>JavaScript is required to run this application.</noscript>
  <div id="root">
    <header class="sc-iCfMLu jjkbpo">
       - header content here -

</body>

</html>

Trying to automate sign-in process for the freshly installed Phantom wallet extension using Selenium, encountering issues with locating and clicking the button element even after implementing WebDriverWait.

Sample code snippet:

- sample code block here -

This code attempts to find and click a specific button element on the Phantom extension's onboard page but encounters errors, such as:

- error messages displayed here -

The desired button element appears as a grey button on the Chrome extension onboard page: chrome-extension://bfnaelmomeimhlpmgjnjophhpkkoljpa/onboarding.html

UPDATED: Upon removing WebDriverWait, an "InvalidArgumentException: invalid locator" is thrown.

Answer №1

The issue is pretty straightforward:

find_element doesn't function in this manner:

phantom_signin = driver.find_element('sc-bdvvtL ljDDId')

instead, it should be like this:

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 with a name such as sc-bdvvtL ljDDId isn't compatible with the use of CLASS_NAME in Selenium + Python bindings due to the lack of support for spaces. You can eliminate the space and replace it with a period to transform it into a valid CSS selector.

Update:

I understand that the class appears to be unique, but the entire HTML structure may not be as expected. Can you please try using the following XPath:

//button[text()='Использовать секретную фразу']

and then click on it using this method:

Code attempt 1:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Использовать секретную фразу']"))).click()

Imports:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

Answer №2

sc-bdvvtL ljDDId actually consists of 2 class names.
To target this element, you can use the following CSS selector:

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, '.sc-bdvvtL.ljDDId')))
    

Alternatively, you can replace the space with a dot by using By.CLASS_NAME:

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CLASS_NAME, 'sc-bdvvtL.ljDDId')))
    

Answer №3

Success! I managed to solve the issue with your help!

The problem was caused by the browser opening the onboarding link instead of Selenium, so it was necessary to focus on that window first.

Here is the revised 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
chop = webdriver.ChromeOptions()
chop.add_extension("res/Phantom 0.14.1.0.crx")
driver = webdriver.Chrome(options=chop)
driver.implicitly_wait(5)

driver.get('chrome-extension://bfnaelmomeimhlpmgjnjophhpkkoljpa/onboarding.html')

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Использовать секретную фразу']"))).click()

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble accepting cookies with Selenium in Python

Currently, I am attempting to conduct web scraping using Selenium in Python. However, my progress is hindered by a popup that appears when a new browser opens, prompting me to accept cookies. This interruption halts the scraping process. The popup displays ...

What is the Firefox Gecko equivalent of the --disable-dev-shm-usage flag found in Chrome?

Welcome to the Docker environment featuring a Docker Container running on ubuntu:18.10 with geckodriver-v0.23.0-linux64 and selenium-3.14.1. While using Chrome, I encountered resource allocation issues in my Docker Container. The problem was resolved by a ...

Getting the h1 text from a div class using scrapy or selenium

I am working with Python using Scrapy and Selenium. My goal is to extract the text from the h1 tag that is within a div class. For instance: <div class = "example"> <h1> This is an example </h1> </div> Here is my implementat ...

Make sure to wait for the stored procedure to finish executing before running the Python script in Node/Express using Tedious

I'm struggling to figure out how to properly time the execution of a python script following the completion of a SQL Server stored procedure via a router.post (express4/tedious): router.post('/post/create', textParser, function (req, res) { ...

The Java/WebDriver element is present, however it was not located within the Chrome Visualforce interface

While conducting WebDriver tests recently, I have encountered TimeoutExceptions even when I am sure that the element is present on the webpage. Take a look at this code snippet: // Wait for page to be partially setup wait.until(visibilityOfElementLoca ...

Press the button using Python's Selenium

I am encountering an issue where I am unable to click the button below and receiving an error message indicating that it cannot be found. <div class="sportsbook-outcome-cell__body selected" aria-label="Thomas Almeida " data-tracking= ...

I just finished creating my own classifier using nltk. Now, how do I go about loading it into textblob?

The default classifier in textblob is not very effective as it is trained on movie reviews. To improve its accuracy, I compiled a large dataset of examples specific to my context (57,000 stories categorized as positive or negative) and used nltk for traini ...

Why is Python BeautifulSoup's findAll function not returning all the elements in the web page

I am attempting to retrieve information from the following URL . Displayed below is the code I have developed. import requests from bs4 import BeautifulSoup url_str = 'https://99airdrops.com/page/1/' page = requests.get(url_str, headers={&apo ...

Struggling to showcase information from a JSON file within an embed on a webpage

I am struggling to display the data from my JSON file in an embed. I need assistance with finding a solution for this issue. Here is the content of the JSON file: { "Slims Mod Bot": { "Felix\u2122": 2, "Dus ...

Attempting to scan through each Reddit headline in order to make a decision on which one to click

I have been attempting to extract the titles of each post in text format, but I've had no luck so far. Each title is enclosed within an h3 tag and my previous approach using this tag has not been successful. Below is the code snippet that I have deve ...

In Python 3, the function sys.stdin.readline() is closely associated with input

When running the Python 3 code snippet below and inputting "Level" as the string, it is returning 3 instead of the expected output of 2. import sys print("Enter a String and I will tell you about it") str = sys.stdin.readline() print(int(len(str)/2) ...

Utilize NLTK in Python to tokenize the word "don't" as "dont"

Whenever I utilize the following: nltk.word_tokenize("cannot") The output I receive is: ["can", "not"] What I am aiming for is: ["cannot"] ...

Using Python dictionaries: When the keys match, simply multiply their corresponding values

I have a code snippet where I am trying to compare two dictionaries and multiply values if the keys match. Here is what I have so far: dict_a = { 'r':100, 'y':110, 'a':210 } print('Enter The Number Of It ...

What is the best approach to interact with and click on a link nested within a button using Selenium

Looking for some assistance. How can I successfully click on a button that is nested inside a div? Currently, I am unable to achieve this action with my current code. Below is the snippet of my code: > WebElement btn_Submit = > driver.findElement(B ...

Generating emails for failed test cases in Selenium WebDriver can serve as a useful tool for quality assurance teams

Having trouble sending email notifications for failed test cases in Selenium WebDriver? Currently, you are able to send generic emails for both passed and failed test cases at the end of the test suite using TestNG framework. However, the specific requirem ...

Single-line ELLIDED QLabel

Currently, I am working on creating a Qlabel in Qt (specifically in PyQt) that will dynamically adjust to the available space. This label is intended to display file paths, which can sometimes be quite lengthy. However, the current setup causes the label t ...

Avoid locating the element within the website

Unable to locate the specified element The code was created using Python with Visual Studio Code from time import time import time from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.by import By ...

"Using Python Regex in Expresso works perfectly, but unfortunately it does not work in Iron

Exploring HTML and diving into learning RegEx, even though I am aware of other approaches. Embracing challenges makes the process interesting... The regular expression I am working with is: publisher.php\?c=.*?\">(.*?)</a>(?:.*?)<br ...

Running Python code from a shell script

Is there a way to incorporate Python code directly into a shell script without relying on an external file? I've done extensive research, but I couldn't find a clear answer. Most solutions involve running an external Python script from the shell ...

Locate all hyperlinks that begin with a space character

I am attempting to locate all hrefs that belong to an 'a' element and begin with 'start/of/link'. I experimented with the following code snippet after discovering it as a resolution to a related question, however, it was ineffective. hr ...