python - Python,Selenium 动作链执行额外任务
问题描述
我的程序的目的是使用 selenium 中的操作键单击 parent_window 上的 URL(在 iframe 中),在新选项卡中打开单击的 URL,在抓取数据后关闭选项卡,然后打开下一个 URL被刮掉。问题是,一旦我尝试打开第二个 URL,它就会打开该 URL 以及之前打开的那个 URL,导致打开 2 个选项卡而不是 1 个。我在 Google Chrome 上。
x = 0
parent_window = driver.current_window_handle
while x < len(url_list): #Going through the URLs on the parent_window
time.sleep(1)
#(ERROR, OPENING UP 2 TABS once x = 1)
actions.key_down(Keys.CONTROL).click(url_list[x]).perform()
#Scrape name and consideration amount
driver.switch_to.window(driver.window_handles[x+1])
last_name.append(driver.find_element_by_xpath("/html/body/table[3]/tbody/tr/td[2]/table/tbody/tr[1]/td[2]/font"))
first_name.append(driver.find_element_by_xpath("/html/body/table[3]/tbody/tr/td[2]/table/tbody/tr[1]/td[3]/font"))
time.sleep(1)
driver.close()
driver.switch_to.window(parent_window)
driver.switch_to.frame("frmeSearchForm")
x = x+1
解决方案
推荐阅读
- java - 从 6.7.7 升级后,Sonarqube 7.9.1 拒绝启动
- javascript - DOMSubtreeModified jQuery 的替代方案
- python-3.x - 如何获取类下 td 标签的值?
- c# - 方法参数参考与值的线程安全
- sql - 如何从选择的最后结果中进行选择
- powerbi - 从 Microsoft Power BI 中表的每一行中减去度量值
- kubernetes - 如何处理 ConfigMaps 中的秘密?
- android - 在本机反应中使用html元素格式化字符串
- c# - 还有什么可能阻止 manifest.json 被提供?
- css - rgba 效果在使用 SASS 或 CSS 变量时不适用