How to interact with a menu featuring an SVG tag by automating it with Selenium

Iā€™m having trouble clicking on a menu button with Selenium on the website . None of my attempts, including using WebDriverWait, seem to work. Can someone please advise me on how I can successfully click on this button using Selenium?

<div class="apexcharts-menu-icon" title="Menu"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0V0z"></path><path d="M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z"></path></svg></div>

Answer ā„–1

SVG is enclosed within a div element, giving you the option to target either the SVG or the div.

If I were to choose the div approach:

driver.maximize_window()
wait = WebDriverWait(driver, 30)

driver.get("https://dappradar.com/binance-smart-chain/defi/drip")

try:
    wait.until(EC.element_to_be_clickable((By.XPATH, "//button[@title='Close']"))).click()
    print('Clicked on closed icon')
except:
    pass

wait.until(EC.element_to_be_clickable((By.XPATH, "//div[@title='Menu']"))).click()

Required 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

My current approach involves using Java to handle the task. To begin, I navigate to a specific location on the page where the desired element is located (usually towards the bottom). Then, I implement an implicit wait to ensure that the element is ready to be interacted with before proceeding to click on it.

        WebDriver driver = new ChromeDriver();
        WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(100));
        driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(50));
        driver.get("https://dappradar.com/binance-smart-chain/defi/drip");
        driver.manage().window().maximize();

        JavascriptExecutor js = (JavascriptExecutor) driver;
        js.executeScript("window.scrollBy(0,350)", "");

        wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("div[title='Menu']")));
        System.out.println("Button enabled:  " + driver.findElement(By.cssSelector("div[title='Menu']")).isDisplayed());
        driver.findElement(By.cssSelector("div[title='Menu']")).click();

        wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector("div[class='apexcharts-menu apexcharts-menu-open']")));

        List<WebElement> elements = driver.findElements(By.cssSelector("div[class='apexcharts-menu apexcharts-menu-open'] > div"));

        System.out.println("List size  " + elements.size());

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

Looking to extract and interpret the content of an Outlook email using Python and convert it into a pandas DataFrame. How can I achieve this task

Looking to extract the body of emails from Outlook and import them into a pandas data frame. How can I separate the msg.Body into individual lines that can be saved to a csv file and then imported into pandas? Currently, this is what I have been able to a ...

Can anyone share the step-by-step process for setting up a dictionary that automatically populates with the necessary sample ID's?

Recently, I've dedicated time to developing a code that streamlines a lab process through automation. In essence, the code is designed to extract experiment data, compile it into a file, and transmit it to the website host for storage. However, I&apos ...

How to add a new column in Python and populate it with the value from the preceding row

As a complete beginner in Python, I am struggling with using the values from the previous row. Despite reading several articles, I still can't seem to grasp the concept. I have an Excel file with sorted data based on the 'D_i' column. Howev ...

Attempting to utilize the default Chrome profile in Selenium with Ruby for testing purposes

At the moment, my Cucumber testing involves using Selenium with Ruby. I came across an issue where the chrome tab created during testing does not have the same settings as my regular browsing Chrome tab. This is a problem because I rely on an extension i ...

Using Selenium for Python-based authentication

Is it possible to automate the launch of admin area URIs on a website using Selenium in a specific browser without prior authentication? If not, what is the best way to handle authentication using Selenium? ...

Ways to update the content of an element

Is there a way to update only the text content of the field1.text element without modifying the entire Python file? Specifically in Python 2.5. import xml.etree.cElementTree as ET import urllib2 import os file("c:\Python25\wxTime.xml", ' ...

Executing multiple m-files in batch on Windows OS without the need to close any previously opened m-file

My goal is to efficiently execute a sequence of m-files and Python programs. Thanks to the contributions of Mofi, Shai, and moarningsun, I have successfully implemented this batch file on my Windows operating system: start "01" /wait "C:\Program Fil ...

When using Eclipse, each workspace must have a unique project name in order to save properly

Hey there! I've done some research on this topic already. It seems that in Eclipse, if you utilize different workspaces, you should be able to save projects with the same name. However, I am encountering difficulties in doing so and I'm not sure ...

Could there be a more efficient method for accessing the file referenced in a Python stack trace?

When faced with a Python stack trace in either Output or Terminal, how can one quickly navigate to the specific file or line where the error occurred? I've noticed that Ctrl-click doesn't work for this purpose. I've been using ctrl-e and man ...

Reorganize the layout of columns in the Flask-Admin list display

In the Flask-Admin list view (ModelView) of my user model, I have successfully excluded some fields and customized headers. The functionality is as expected, and I have even taken the extra step to modify the default list template so it aligns with the sty ...

Challenges with leveraging Select2 with Bootstrap design styling

I'm currently working on styling my form using Bootstrap. One of the challenges I've encountered is with a django-autocomplete-light control that utilizes Select2 to query the database on the back-end. In an attempt to enhance the design, I expl ...

Utilizing XPath with Selenium in VBA

In my search for a node based on text located within a child or grandchild node of its immediate sibling, I came across the following HTML structure: <div> <div class="searchedDivClass" id="DynamicId1"> </div> <div class=" ...

Is Pykka about slow actors?

I'm currently delving into Actor-concurrency in Python to enhance my understanding. I decided to use pykka, but upon testing, it seems to be over twice as slow compared to a regular function. The code is just for testing purposes and not intended to ...

Issue with the lxml version - encountering difficulty in invoking the findall method!

An error occurs in lxml version 1.3 for the following line of code: self.doc.findall('.//field[@on_change]') File "/home/.../code_generator/xmlGenerator.py", line 158, in processOnChange onchangeNodes = self.doc.findall('.//field[@on_chan ...

Wait for the Selenium test to continue only when a specific element is visible on

<img style="width: 640; height: 640;" id="img108686545" alt="Loading Word War..." src="www.something.com/anu.jpg"> Is there a way to detect when this particular element is visible on the page? The value of the "id" attributes keeps changing with eac ...

Condense Python Dictionary to Boolean Values

Imagine having a Python dictionary with nested dictionaries to any level and a mix of keys representing boolean choices and others that don't. For example: {'Key1': 'none', 'Key2': {'Key2a': True, 'Key2b& ...

Scrapy is unable to crawl past page 2 when listing bugs

I'm having some trouble scraping a list of resolved Chrome bugs. The scraper is working well for the first and second pages, but for some reason, it's stopping at the third page. I've set DEPTH_LIMIT = 1 in setting.py. Could this issue be re ...

Create a Django queryset with an annotated field that returns a list or queryset

Looking for guidance on utilizing Django annotation to generate a queryset field that contains a list of values from a related model attribute. queryset = ... qs = queryset.annotate( list_field=SomeAggregateFunction( Case(When(related_model__f ...

Creating unique IDs that start from 1 and increment by 1 each time a specific value is encountered in a different column can be achieved by implementing a step-by-step

In my Python project, I am looking to generate a unique Journey ID and Journey number. The goal is to increment the ID each time the previous row in the "Purpose" column equals 1, while the Journey number should do the same but within each Respondent ID gr ...

Difficulty accessing CSV files in Pandas due to KeyError

I have successfully used pandas to create a CSV file, but I encountered an error during the process: Traceback (most recent call last): File "C:\Users\Manoj Kumar\PycharmProjects\trex\venv\lib\site-packages\pandas ...