1

I have tried to select the element below using xpath, id, class, nothing is working. This is the error message:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="ui-id-26"]"}

HTML code of the element:

<a title="" href="#8eef8ef4-7cfc-4cb6-69cf-1cabf9625d74" class="ui-tabs-anchor" role="presentation" tabindex="-1" id="ui-id-26">Data</a>

Snapshot of the element:

the element I want to select and eventually click

I am using python.

This is my code:

from selenium import webdriver
from selenium.webdriver.common.by import By
import time
chromedriver = 'C:/Users/misha/Downloads/chromedriver_win32/chromedriver'

driver = webdriver.Chrome(chromedriver)
driver.get("https://login.cmegroup.com/sso/accountstatus/showAuth.action")
driver.maximize_window()
login = driver.find_element(By.ID, "loginBtn")

name = driver.find_element(By.ID, "user")
name.send_keys("MyEmail")
pwd = driver.find_element(By.ID, "pwd")
pwd.send_keys("MyPassword")
login.click()

time.sleep(15)

driver.get('https://www.cmegroup.com/trading/fx/cme-fx-market-profile-tool.html#analyze-more')


data = driver.find_element(By.XPATH,'//*[@id="ui-id-26"]')

data.click()


undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • import time and try to add a time.sleep(5) between data and driver.get(url) –  Feb 18 '22 at 12:37
  • 1
    If possible add HTML snippet for the page. Also make sure that element you want to interact is not within the `iframe` – Krishna Majgaonkar Feb 18 '22 at 12:41
  • The element `Id` could be dynamic or If not then element could be inside an `iframe`. You need to post the relevant html for better solutions. – KunduK Feb 18 '22 at 12:44
  • Update the question with text based relevant HTML of the element. – undetected Selenium Feb 18 '22 at 13:03
  • /html/body/div/div[1]/div/div[1]/div[1]/div[2]/div[1]/div[2]/div[9]/div/div[1]/div[2]/div[2]/div[1]/div[2]/div[9]/div/div[1]/div[2]/div/div[2]/div[2]/div[1]/div[2]/div[2]/div[1]/div[3]/div[9]/div/div[1]/div[2]/div[2]/div[1]/div[2]/div[9]/div/div[1]/div[2]/div/ul/li[2]/a is the full xpath @undetected Selenium if this helps – Misha Jiltsov Feb 18 '22 at 13:23

1 Answers1

1

To click on the element with text as Data you can use either of the following locator strategies:

  • Using link_text:

    driver.find_element(By.LINK_TEXT, "Data").click()
    
  • Using css_selector:

    driver.find_element(By.CSS_SELECTOR, "a.ui-tabs-anchor[id^='ui-id'][title]").click()
    
  • Using xpath:

    driver.find_element(By.XPATH, "//a[@class='ui-tabs-anchor' and starts-with(@id, 'ui-id')][text()='Data']").click()
    

The desired element is a dynamic element, so ideally to click() on the clickable element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using LINK_TEXT:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "Data"))).click()
    
  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.ui-tabs-anchor[id^='ui-id'][title]"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='ui-tabs-anchor' and starts-with(@id, 'ui-id')][text()='Data']"))).click()
    
  • Note: You have to add the following imports :

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

References

You can find a couple of relevant discussions on NoSuchElementException in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352