Python 3.x 在JS页面和Python窗口之间切换
Python 3.x 在JS页面和Python窗口之间切换,python-3.x,selenium,web-scraping,Python 3.x,Selenium,Web Scraping,driver.switch_to.window函数是否与Selenium Python的Javascript页面一起工作 这个问题与driver.switch_to.window是否适用于JS页面有关。这与我最近的发现不符 我最近在我的项目中发现它不起作用。我使用了在浏览器中使用后退按钮的变通方法 from selenium import webdriver import time from selenium.webdriver.common.keys import Keys import pd
driver.switch_to.window
函数是否与Selenium Python的Javascript页面一起工作
这个问题与driver.switch_to.window是否适用于JS页面有关。这与我最近的发现不符
我最近在我的项目中发现它不起作用。我使用了在浏览器中使用后退按钮的变通方法
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
这是我使用的代码。我正在使用Selenium进入谷歌,使用关键词并下载位置栏中的数据。在这里,我尝试使用driver.switch_to.window
,而不是最后执行scriptcmd(浏览器后退按钮),但效果不佳
因此,我再次想知道driver.switch_to.window是否在JS页面上工作。@DebanjanB:在标记之前,你能阅读问题吗?这个问题与driver.switch_to.window是否适用于JS页面有关。它不涉及如何在Selenium Python中切换窗口,你可以定义“Javascript页面”?@Akshay你所说的JS页面到底是什么意思?你能用你的代码测试更新这个问题吗?@DebanjanB我已经编辑了这篇文章。请看一下,让我看看know@pcalkins.I我已经编辑了这篇文章。请看一看,让我看看know@DebanjanB:你能在批改前阅读问题吗?这个问题与driver.switch_to.window是否适用于JS页面有关。它不涉及如何在Selenium Python中切换窗口,你可以定义“Javascript页面”?@Akshay你所说的JS页面到底是什么意思?你能用你的代码测试更新这个问题吗?@DebanjanB我已经编辑了这篇文章。请看一下,让我看看know@pcalkins.I我已经编辑了这篇文章。请看一看并让我知道