我在用谷歌有头模式点击网页可以正常点击访问 于是我又用phantomjs就报元素不存在(这里用的是老版本的) 然后我又用谷歌无头模式访问 也能正常访问
这是为什么呢?
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
def start():
#targets = Options()
#targets.add_argument('--headless')
#targets.add_argument('--disable-gpu')
path = r'chromedriver.exe'
name=input('搜索:')
muscienc=f'https://www.musicenc.com/?search={name}'
#target=webdriver.Chrome(executable_path=path,chrome_options=targets)
target=webdriver.PhantomJS('phantomjs.exe')
target.get(muscienc)
target.implicitly_wait(6)
target.find_element_by_xpath('/html/body/div[2]/div[2]/li[1]/a').click()
time.sleep(5)
allhandle=target.window_handles
target.switch_to.window(allhandle[1])
time.sleep(5)
open=target.find_element_by_xpath('/html/body/div[2]/div[3]/a')
open.click()
if __name__ == '__main__':
start()