0

Trying to find the xpath for the <nobr> tag at the bottom of the page and it's driving me crazy. The frames are what is complicating the issue. Can someone please tell me the xpath for this?

I am trying to write a selenium script and I have gotten to:

EC.frame_to_be_available_and_switch_to_it, ((By.NAME, "main"))

After that none of my xpath attempts have worked to get the content in the <nobr> tag where it says supplier.

HTML:

html screenshot

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • `//span[@class="tabSelText"]` ? if there are several entries, add nodes before span – Vova Feb 26 '20 at 17:56
  • I understand that part but I'm going wrong with frames somewhere after main. Has anyone any ideas regards that. I've spent way too long trying to figure this out already – Thomas Cawley Feb 26 '20 at 18:02
  • They are nested frames so you'll have to traverse those. You'll probably have to switch to the frameset first to get the 2nd frame. Then switch to the frameset inside that frame... then switch to the frame inside that frameset, and that's where your span is. – pcalkins Feb 26 '20 at 18:15
  • Thanks pcalkins. I got a little further down but the next frameset has no id. Will that be possible? frames are new to me when it's this complicated – Thomas Cawley Feb 26 '20 at 18:19
  • This is the next and hopefully final frameset, just not sure how to get into it – Thomas Cawley Feb 26 '20 at 18:20

3 Answers3

0

Another option :

//nobr[.='Suppliers']/parent::span

For the frameset :

//frameset[@rows='48,*']
E.Wiest
  • 5,425
  • 2
  • 7
  • 12
0

As the the desired element is within multiple neted <iframe> so to invoke click() on the element you have to:

  • Induce WebDriverWait for the great grand parent frame_to_be_available_and_switch_to_it().
  • Induce WebDriverWait for the grand parent frame_to_be_available_and_switch_to_it().
  • Induce WebDriverWait for the parent frame_to_be_available_and_switch_to_it().
  • Induce WebDriverWait for the desired element_to_be_clickable().
  • You can use the following solution:

    • Using CSS_SELECTOR:

      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe#main[name='main']")))
      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[name='marketcenterHome']")))
      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe#main[name='TabNavigation']")))
      element = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span.tabSelText>nobr")))
      
    • Using XPATH:

      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@id='main' and @name='main']")))
      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@name='marketcenterHome']")))
      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@name='TabNavigation']")))
      element = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[@class='tabSelText']/nobr[text()='Suppliers']")))
      
    • 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
      

Reference

You can find a couple of relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thanks for the detailed response. I seem to be having an issue where I cannot switch to main as it cannot be found. I have successfully switched into the title frame before this on the same level as main and clicked a link. Is there something I need to do to exit title before I select main? – Thomas Cawley Feb 27 '20 at 00:24
  • Fixed it. I'll post the solution tomorrow – Thomas Cawley Feb 27 '20 at 01:46
0

Apologies for the delay in coming back with the solution but the problem was that I needed to go up a level from the title iframe to get myself into root and then I was able to go down into main. A simple problem to have but not so simple when you don't know too much about frames at the time. I appreciate everyone who took the time to answer.