Does driver.switch_to.window
Function work with Javascript Pages for Selenium Python?
The question relates to whether driver.switch_to.window would work with JS Pages. It doesnt as per my recent finding.
I recently discovered in my project that it doesnt work.I used the work around of using the back button in browser
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
import pdb
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
chrome_path=r'C:\webdrivers\chromedriver.exe'
driver=webdriver.Chrome(chrome_path)
url='https://www.google.com/'
URL_List=['1line williams']
for i in range(0,2):
driver.get(url)
SearchPage = driver.window_handles[0]
searchbar=driver.find_element_by_name('q')
time.sleep(2)
searchbar.send_keys(URL_List[i])
searchbar.send_keys(Keys.ENTER)
if i==2:
PipelineID=1
SelectLink=driver.find_element_by_xpath('//*[@id="rso"]/div[1]/div/div/div/div/div[1]/a/h3').click()
time.sleep(2)
Links=driver.find_elements_by_class_name("links")
aElements = driver.find_elements_by_tag_name("a")
for name in aElements:
window_after=driver.window_handles[0]
time.sleep(5)
SelectPipeline=driver.find_element_by_xpath('//*[@id="splashContent_pipelines"]/div['+str(PipelineID)+']/p[2]/a[1]').click()
time.sleep(2)
Location=driver.find_element_by_xpath('//*[@id="navmenu-v"]/li[4]/a').click()
time.sleep(2)
File=driver.find_element_by_xpath('//*[@id="navmenu-v"]/li[4]/ul/li/a').click()
time.sleep(15)
document=driver.find_element_by_tag_name('iframe')
driver.switch_to.frame(document)
time.sleep(2)
DownloadFile=driver.find_element_by_xpath('//*[@id="list:downloadBtn"]').click()
time.sleep(2)
driver.execute_script("window.history.go(-2)")
PipelineID=PipelineID+1
time.sleep(3)
if PipelineID>3:
driver.quit()
break
This is the code Im using. Im using Selenium to go to google use the keyword and download data in Location column. Here I tried using driver.switch_to.window
instead of execute script cmd at last(browser back button)but it dint work
So once again I would like to know if driver.switch_to.window works on JS Pages or not.