0

The webpage (see driver.get() below) seems to have one table with class name as table. I can't seem to locate it using the code below.

I was under the impression that I could locate these type of Javascript elements using Selenium.

import time

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

driver.quit()
driver = webdriver.PhantomJS()

driver.get('http://investsnips.com/list-of-publicly-traded-micro-cap-diversified-biotechnology-and-pharmaceutical-companies/')


content = driver.find_element_by_css_selector('table.table')
x = driver.find_element_by_class_name("table")

I'm getting this error (content nor x work)

NoSuchElementException: Message: {"errorMessage":"Unable to find element with class name 'table'","request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"94","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:49464","User-Agent":"Python http auth"},"httpVersion":"1.1","method":"POST","post":"{\"using\": \"class name\", \"value\": \"table\", \"sessionId\": \"a988f310-65da-11e7-a655-01f6986e9e41\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/a988f310-65da-11e7-a655-01f6986e9e41/element"}}
Screenshot: available via screen
2
  • Which element are you exactly trying to locate? Commented Jul 11, 2017 at 3:13
  • Please add the relevant HTML fragment (extraced via the development tools; F12) to your question by editiing. The link is volatile and your question will be useless if the link changes in the future. Commented Jul 13, 2017 at 4:58

1 Answer 1

1

The table in in iframe. You have to switch iframe before finding the table. See code below.

driver = webdriver.PhantomJS()

driver.get('http://investsnips.com/list-of-publicly-traded-micro-cap-diversified-biotechnology-and-pharmaceutical-companies/')

#Find the iframe tradingview_xxxxx and then switch into the iframe
iframeElement = driver.find_element_by_css_selector('iframe[id*="tradingview_"]')
driver.switch_to_frame(iframeElement)
#Wait for the table
waitForPresence = WebDriverWait(driver, 10)
waitForPresence.until(EC.presence_of_element_located((By.CSS_SELECTOR,'table.table'))
theTable = driver.find_element_by_css_selector('table.table')
Sign up to request clarification or add additional context in comments.

2 Comments

I see. Going to run some tests on you code. Thank you so much =)
Hi, Are you importing something for the wait in wait.until(EC.presence_of_element_located((By.CSS_SELECTOR,'table.table')). I don't see any wait variable assignments in your code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.