selenium自动化-同一个窗口打开网页,只适用于有这个target="_blank"属性链接情况

# coding:utf-8
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.select import Select
import  time
driver = webdriver.Chrome()

driver.get("https://www.baidu.com/")
time.sleep(3)

# 修改元素的target属性,只适用于有这个target="_blank"属性链接情况
js = 'document.getElementsByClassName("mnav")[0].target="";'
time.sleep(3)
driver.execute_script(js)
time.sleep(3)
driver.find_element_by_link_text("新闻").click()

你可能感兴趣的:(selenium自动化)