How to choose the correct iframe in Selenium WebDriver?

0 votes

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

url = ''
driver = webdriver.Firefox()

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')

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:


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,330 points

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()

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
1 answer

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

Its pretty simple. Check out the below ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,510 points
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
+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
0 votes
1 answer

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
0 votes
1 answer
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
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,890 points
+9 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,370 points
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