How to choose the correct iframe in Selenium WebDriver

0 votes

I'm trying to click on an element on this page:

url = 'https://finance.yahoo.com/quote/GOOG?ltr=1'
driver = webdriver.Firefox()
driver.get(url)
driver.find_element_by_link_text('Financials')

This instant I want to click on buttons like 'Cash Flow', or 'Balance Sheet', or 'Quarterly'. I'm aware that these by now these are loaded as I manually extracted them using BeautifulSoup by performing a page source. But when I try the same using Selenium, I'm out of luck.

driver.find_element_by_link_text('Cash Flow')
driver.find_element_by_link_text('Balance Sheet')
driver.find_element_by_link_text('Quarterly')

Every line here returns 'Unable to locate element' besides 'Quarterly'. This returns an element but its not the one I want. I guess its because of choosing the wrong iframe, and I have located all iframes:

driver.find_elements_by_tag_name('iframe')

This returns 9 elements. But, I'm not able to figure out the iframe of the element that I need to click on. I also went through the iframes sequentially and still couldn't find the elements I'm interested in.

Apr 29, 2018 in Selenium by Martin
• 4,320 points
1,692 views

1 answer to this question.

0 votes

When I checked the website you've mentioned, I saw that the elements your loooking for are not in IFrames. So, the following worked for me though.

driver.find_element_by_xpath("//span[contains(text(),'Cash Flow')]").click()
driver.find_element_by_xpath("//span[contains(text(),'Balance Sheet')]").click()
driver.find_element_by_xpath("//span[contains(text(),'Quarterly')]").click()


Maybe the reason it didn't work for you is because "Financials" had <a> as parent tag but for others, the parent tag is <div>. And since <div> is not a link tag, link_text might not have worked for you.

answered Apr 29, 2018 by king_kenny
• 3,710 points

Related Questions In Selenium

0 votes
2 answers

How to scroll the Page up or down in Selenium WebDriver? (using java)

JavascriptExecutor jsx = (JavascriptExecutor)driver; jsx.executeScript("window.scrollBy(0,555)", ""); or Action classes ...READ MORE

answered Sep 6, 2020 in Selenium by Sri
• 3,190 points
18,955 views
0 votes
1 answer

How to eliminate this error”Cannot instantiate the type Select in selenium webdriver”

Try below code. Select sc = new Select(driver.findElement(By.xpath("your ...READ MORE

answered May 18, 2018 in Selenium by Samarpit
• 5,910 points
10,001 views
+1 vote
1 answer
0 votes
1 answer

How to get the select options using Selenium WebDriver in Java

Hey there! You should be able to get ...READ MORE

answered Jun 14, 2019 in Selenium by Surya
• 970 points
4,764 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
13,747 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,178 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
7,253 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,890 views
+10 votes
17 answers

How to automate gmail login process using selenium webdriver in java?

Check the below code: Here is the working ...READ MORE

answered Apr 24, 2018 in Selenium by Vardy
• 2,360 points
198,196 views
0 votes
1 answer

How to choose from a drop-down in Selenium 2?

You can probably use the 'Select' class ...READ MORE

answered Apr 24, 2018 in Selenium by king_kenny
• 3,710 points
1,169 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP