【发布时间】:2018-11-15 17:55:07
【问题描述】:
所以我试图在 Chrome 上打开一个新标签页,其中 URL 是一个字符串。我这样做是因为动作链或键似乎都不起作用。此代码的目的是从选定元素打开一个新选项卡,但我似乎无法打开具有正确网站的新页面。
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
import time
import random
chromedriver = "\Program Files\webdrivers/chromedriver"
driver = webdriver.Chrome(chromedriver)
driver.get("https://google.com")
time.sleep(3)
for a in driver.find_elements_by_xpath('//*[@id="prm"]/div/a'):
A = str(a.get_attribute('href'))
driver.execute_script("window.open('A');")
【问题讨论】:
-
给定 url [google.com] 的 xpath 是否正确?找不到任何这样的定位器。
-
它来自荷兰谷歌网站,但您可以使用任何有效的 xpath。我只是想让它工作
标签: python selenium selenium-webdriver