I am using selenium in a personal project, and i want to create a new tap. i read the selenium documentation about it and found this method:
# Opens a new tab and switches to new tab
driver.switch_to.new_window('tab')
But when i run this code, it throws:
AttributeError: 'SwitchTo' object has no attribute 'new_window'
So i find this question about creating new tabs and find this. It works for me, but my question is if for you that method works. i also saw the selenium api and i could not find that method in the WebDriver module.
i am using:
- firefox 96.0
- geckodriver v0.30.0
- python 3.9.7
- selenium 4.1.0
- jupyter notebook 6.4.5
Here is the part of the code:
for grade in grades:
grade.click()
div_classes= WebDriverWait(grade, 5).until(EC.element_to_be_clickable((By.CSS_SELECTOR, '.in')))
div_rows= div_classes.find_element(By.CSS_SELECTOR, '.row')
if len(div_rows.find_elements(By.TAG_NAME, 'div')) > 0:
a= div_rows.find_element(By.TAG_NAME, 'a')
original_window = driver.current_window_handle
driver.switch_to.new_window('tab')
driver.get(a.get_dom_attribute('href'))
Here is the html part of the page (to get the grades there is some js that it is executed):
<div class="row">
<div class="col-xs-12 col-md-6 col-lg-4 entity-col">
<a href="www.google.com">
<div class="entity-item-object" style="background-color:#3a87ad">
</div>
</a>
<div class="btn-pref btn-group btn-group-justified" role="group">
<a href="" data-original-title="Proyectos">
<span class="icon-uno class-projects icon-xxl visible"></span>
</a>
<a href="" title="" role="button" class="btn btn-class-menu pretty-tooltip" data-original-title="Actividades">
<span class="icon-uno files icon-big visible"></span>
</a>
<a href="" title="" role="button" class="btn btn-class-menu pretty-tooltip" data-original-title="Bibliotecas de clase">
<span class="icon-uno class-book icon-xxl visible"></span>
</a>
<a href="" data-original-title="Foro">
<span class="icon-uno bubbles icon-big visible"></span>
</a>
<a href="" data-original-title="Calendario">
<span class="icon-uno calendar icon-big visible"></span>
</a>
</div>
</div>
<div class="col-xs-12 col-md-6 col-lg-4 entity-col">
<!-- this div is the same as above but with different info, and there is some more divs with the same estructure under the '<div class="row">'
</div>