trying to get href using selenium

Question:

I am trying to get href but they give me nothing these is page link https://www.nascc.aisc.org/trade-show

import time
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait


driver = webdriver.Chrome("C:Program Files (x86)chromedriver.exe")
URL = 'https://www.nascc.aisc.org/trade-show'
driver.get(URL)

page_links =[element.get_attribute('href') for element in
                      driver.find_elements(By.XPATH, "//table[@class='ffTableSet table table-striped']//a[starts-with(@href, 'https://n2a.goexposoftware.com/events/nascc23/goExpo/exhibitor')]")]

print(page_links)
    
Asked By: developer

||

Answers:

The element is inside nested iframe you need to switch to both frames.

URL = 'https://www.nascc.aisc.org/trade-show'
driver.get(URL)

WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[name='htmlComp-iframe']")))
WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe#geFrame1")))
time.sleep(5)
page_links =[element.get_attribute('href') for element in
                      driver.find_elements(By.XPATH, "//table[@class='ffTableSet table table-striped']//a[starts-with(@href, 'https://n2a.goexposoftware.com/events/nascc23/goExpo/exhibitor')]")]

print(page_links)

You need to import below libraries

from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
import time
Answered By: KunduK

Here’s how to avoid dealing with iframes on that page: (Go directly to the inner site)

from selenium import webdriver

driver = webdriver.Chrome()
URL = 'https://n2a.goexposoftware.com/events/nascc23/goExpo/public/listExhibitorsFrame.php'
driver.get(URL)
page_links = [element.get_attribute("href") for element in
                driver.find_elements("css selector",
                    '[href*="nascc23/goExpo/exhibitor"]')]
print(page_links)
driver.quit()
Answered By: Michael Mintz