python - selenium change frame not working

1.5k Views Asked by At

im trying to navigate a webpage so as to download some csv files. The thing is that there is a dropdown and everytime you change it the page reloads. So im trying to use selenium so as to get work around this issue.

The webpage has 2 frames. On the name="left" frame its the dropdown. so i use the following code to access that frame:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import WebDriverException

print os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..', 'driver')+'\\chromedriver.exe')
chromedriver_path =os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..', 'driver')+'\\chromedriver.exe')
driver = webdriver.Chrome(chromedriver_path)
driver.implicitly_wait(10)
driver.get(url2)
frames = []
frames = driver.find_elements_by_tag_name('frame')
for frame in frames:
    print frame.get_attribute('name')

driver.switch_to_frame('left')

elements = []
elements = driver.find_elements_by_xpath('//select')

print elements

sadly the output is the following:

left
right
[]

the frame names are found but when i do the search of the combobox it doesnt work.

main-frame

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<frameset cols="600,*" id="frMain" name="frMain">
  <frame id="left" name="left" src="">
  <frame id="right" name="right" src="" frameborder="0" noresize="noresize" scrolling="no">
</frameset>
</html>

left frame

<!DOCTYPE html>
<html>
<head>
</head>
<body onload="Init()">
<table border="0" cellspacing="0" cellpadding="0" style="width: 100%">
<tr align="left" valign="top">
    <td>&nbsp;</td>
    <td>
      <tr>
        <td colspan="1">
            <select id="ic" name="ic" onchange="EnablePeriod();Open()" style="width: 240px;">
                <option></option>
                <option></option>
1

There are 1 best solutions below

0
On

The following should work -

leftframe = driver.find_element_by_name('left')
driver.switch_to.frame(leftframe)

elements = []
elements = driver.find_elements_by_xpath('//select')

print elements