0

I'm scanning a website to check if a certain script exists on the site. I have been successful in extracting this information from most sites but there are a few which is causing trouble for me eg. 247sports.com, where I'm unable to get this information the DOM looks like this

...

<iframe src='...'>
  <!DOCTYPE html>
  <html lang..>
  <head>
  <iframe> ...</iframe>
  ...
  <script id="utag_81" src="https://js.agkn.com/prod/v0/tag.js?_rnd=0.6281110988358267" type="text/javascript" charset="utf-8" async=""></script>
  ...
</iframe>

I'm using Firefox Webdriver to look for the "agkn" string in src="https://js.agkn.com/prod..."

Python code:

x = Webdriver.find_elements_by_xpath("(//iframe|//script|//img|//a)[contains(text(),'agkn') or contains(@src,'agkn') or contains(.,'agkn') or contains(@id,'utag_81') ]")

the length of x is always 0.

does the <!DOCTYPE html> have something to do with this?.

tribs
  • 1
  • 2
  • You need to switch to the desired frame to retrieve the contents from the ` – undetected Selenium May 10 '18 at 19:36

1 Answers1

0

if you have iframes in your code, you need to switch to that iframe first and get element from that level.

Sample code:

self.driver = webdriver.Firefox()
driver.switch_to.frame(driver.find_element_by_tag_name("iframe"))
elem = driver.find_element_by_xpath("/html/body/img") 
parishodak
  • 4,506
  • 4
  • 34
  • 48
  • for some reason switch_to_frame( Name/ID) kept giving me issues so I used the switch_to.frame(i) and it worked like a charm – tribs May 11 '18 at 01:15
  • my mistake. correct syntax is switch_to.frame(i) as you mentioned. edited post as well. – parishodak May 12 '18 at 03:00