Struggling to find a specific element on a website with Xpath in Selenium using Python

Attempting to retrieve data from a website named: , specifically targeting the element: /html/body/div[1]/div/main/div/div[2]/div/div[2]/div/div/div[1]/div[4]/div[2]/div[1]/div[1]/div[2]/span[2] which displays volume as a number on the webpage.

The code I utilized is shown below:

driver.get('https://dexscreener.com/ethereum/' + str(tokenadress))
try:
    fivemVolume = WebDriverWait(driver, delay).until(EC.presence_of_element_located(
        (By.XPATH,         '/html/body/div[1]/div/main/div/div[2]/div/div[2]/div/div/div[1]/div[4]/div[2]/div[1]/div[1]/div[2]/span[2]')))
except:
   #more codee

I suspect that the issue may be related to the webpage loading within an iframe by default. I attempted to resolve this by inserting the following code without success:

driver.switch_to.default_content()

Answer №1

We couldn't find the locator matching any element on this page.
The elements you are trying to access are inside an iframe.
Therefore, you must first switch into the iframe.
I encountered issues while running Selenium on that specific page as it is being blocked by cloudflare:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

options = Options()
options.add_argument("start-maximized")

webdriver_service = Service('C:\webdrivers\chromedriver.exe')
driver = webdriver.Chrome(options=options, service=webdriver_service)
wait = WebDriverWait(driver, 30)

url = "https://dexscreener.com/ethereum/0x1a89ae3ba4f9a97b10bac6a77061f00bb956858b"
driver.get(url)

wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[id*='tradingview']")))

value = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "[data-name='legend-source-item'] [class='valueItem-1WIwNaDF'] .valueValue-1WIwNaDF"))).text
print(value)

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

Is there a way to execute automated selenium tests using TFS build 2015?

My NUnit selenium tests are integrated into Unit test and they work perfectly fine when run locally, but not on the TFS Server. After enabling code coverage, I noticed that "Module unittests.dll" was covering most of the code, while "Seleniumtest.exe" had ...

What is the best way to input numerical data into an input field with Python utilizing Selenium?

I am encountering an issue with my script that is writing values into a web page. All values are successfully written except for one field, which consistently displays the error message: https://i.stack.imgur.com/qzx65.png (A screenshot has been included b ...

Python code for arranging the output in numerical sequence

My program reads the last line of multiple files simultaneously and displays the output as a list of tuples. from os import listdir from os.path import isfile, join import subprocess path = "/home/abc/xyz/200/coord_b/" filename_last_l ...

Troubleshooting problem in Django with fetching JSON data using requests

In working with my front-end server, I'm receiving JSON data from the backend server, both of which are powered by Django. Here's the snippet of code responsible for fetching the JSON data: def RetrieveData(request): r = requests.get(path) r ...

How to retrieve values from a ForeignKey field in Django model instances

My project involves creating a user-friendly webshop platform where users can easily set up their own shops, choose product categories, and add products to sell. To bring this vision to life, I have developed a simplified models.py file: class Organizati ...

Unable to interact with cookies using Python's selenium package

My current project involves using Python, Selenium, and PhantomJS to access a webpage. After getting the page with driver.get and logging in, I received a notification that cookies needed to be enabled. In an attempt to access these cookies, I implemented ...

Guide on Selenium drivers for Firefox and Internet Explorer

Seeking detailed and advanced tutorials on Selenium web driver for exporting test cases from IDE to Eclipse. Experienced success with FF but encountering issues with IE. Looking to enhance my skills in using Selenium. Any recommendations for comprehensiv ...

The Chrome Driver indicates compatibility with version 114, but it is actually intended to support version 113 - as mentioned in Selenium Python

from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.chrome.service import Service from webdriver_manager.chrome import ChromeDriverManager from time import sleep driver = webdriver.Chrome(service=Service(Chr ...

Extract web traffic data from Semrush using Beautiful Soup in Python

I'm currently attempting to extract website traffic data from semrush.com using BeautifulSoup. My existing code utilizing BeautifulSoup looks like this: from bs4 import BeautifulSoup, BeautifulStoneSoup import urllib import json req = urllib.reques ...

Converting a source-target-weight dataframe into a JSON file

I have these three dataframes - source, target, and weight : source target weight 0 A B 3 1 A C 2 2 B C 0 3 C D 1 4 D ...

Export Page Elements from Selenium to a File

I've created a script using Selenium IDE for Firefox on Windows 7 with FF 25.01 IDE version 2.4.0. The script is functioning well, but I'm interested in saving a particular page element from the query it executes to a text file. The page being l ...

What is the best way to format a list for writing into a file?

I am working with a Python list and I want to format it in a specific way. Input: trend_end= ['skill1',10,0,13,'skill2',6,1,0,'skill3',5,8,9,'skill4',9,0,1] I need the file to look like this: Output: 1 2 3 1 ...

Merge the latter portions of several arrays

Looking to combine two arrays with identical shapes, like so: array1= (1230000,32) array2= (1230000,32) array3= (1230000,32) The desired result would be res1= array1+array2: (1230000,64) res2= array1+array2+array3: (1230000,96) I attempted to achieve thi ...

What is the best way to display a table in Python?

I'm attempting to display the output of this code in two columns using the Python launcher: def main(): print "This program demonstrates a chaotic function" n = input("How many numbers would you like to see? ") x = input("Enter a number b ...

What are some methods to execute a line of code in the event that the button is not present within my IF statement

After receiving assistance from a member on this platform, I managed to get this code to function correctly: boolean clickMore = true; while(clickMore == true) { List<WebElement> button1 = driver.findElements(By ...

The reference to the global name 'start' is not recognized: Tkinter

Encountering the error message "Global name 'start' is not defined" from the code snippet provided. Interestingly, the call to start(panel) within displayImage(img) is responsible for displaying the desired image in the GUI; without it, no image ...

When saving data to a CSV file in Python, the information is separated by commas, ensuring each character is properly recorded

Trying to read data from a CSV file and then write it to another one. However, the written data is separated by commas. Below is the code snippet: with open(filenameInput, 'r') as csvfile: dfi = pd.read_csv (filenameInput) dfi - dfi.ilo ...

scraping mixed content from an HTML span using Selenium and XPath

Currently, I am attempting to extract information from a span element that contains various content. <span id="span-id"> <!--starts with some whitespace--> <b>bold title</b> <br/> text here that I want to grab.... < ...

Mapping Coordinate Points on a Three-Dimensional Sphere

I am having trouble generating uniformly distributed points on a sphere. The current code seems to be creating points that form a disk shape instead of being spread evenly across the surface of the sphere. I suspect that the issue lies in the calculation f ...

clicking on a download link to retrieve a CSV file from a webpage

I am currently experiencing an issue with downloading a csv file from a website that requires login. Using Selenium, I have managed to successfully log in. However, I am unsure of how to proceed with downloading the csv file by clicking on a button. Despit ...