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,340 points
618 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 5 in Selenium by Sri
• 2,970 points
13,275 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,890 points
4,189 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 13, 2019 in Selenium by Surya
• 970 points
1,517 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,510 points
3,545 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

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

answered Aug 31 in Selenium by Sri
• 2,970 points
4,550 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,890 points
2,602 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 2 in Selenium by Sri
• 2,970 points
2,874 views
+10 votes
15 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
119,327 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
351 views