Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用python selenium关闭另一个chrome弹出窗口_Python_Selenium_Selenium Webdriver_Web_Web Scraping - Fatal编程技术网

如何使用python selenium关闭另一个chrome弹出窗口

如何使用python selenium关闭另一个chrome弹出窗口,python,selenium,selenium-webdriver,web,web-scraping,Python,Selenium,Selenium Webdriver,Web,Web Scraping,这是我的密码: import os from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver import ActionChains from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.by import By from seleni

这是我的密码:

import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from time import gmtime, strftime
from os import system
import pyperclip
import datetime
import time
import os
import sys



executable_path = r"C:\Users\Administrator\Desktop\chromedriver_win32\chromedriver.exe"
os.environ["webdriver.chrome.driver"] = executable_path
chrome_options = Options()
chrome_options.add_extension(r'C:\Users\Administrator\Desktop\chromedriver_win32\extension.crx')
driver = webdriver.Chrome(executable_path=executable_path, chrome_options=chrome_options)
time.sleep(4)
driver.get("https://www.tradingview.com/chart/gK6Rq0UH/")
time.sleep(4)
driver.find_element_by_xpath("""//*[@id="footer-chart-panel"]/div[2]/span[4]""").click()
time.sleep(4)
while True:
    driver.find_element_by_xpath("""//*[@id="bottom-area"]/div[2]/div[1]/div[2]/ul/li[4]""").click()
    time.sleep(2)
    contents = pyperclip.paste()
    time.sleep(2)
    filepath = r"C:\Users\Administrator\Desktop\DATA.txt"
    time.sleep(2)
    with open(filepath, 'w') as f: # 'w' means write mode and we get the file object as f
        f.write(contents)
        time.sleep(5)   
我试过这个代码,但没用

driver.switchTo().alert().accept();
这个代码也不起作用

driver.send_keys("Enter")
若我右键单击弹出窗口,那个么根本并没有任何操作,所以我找不到XPath,类id

试试这个:


驱动程序。切换到报警().accept()

您是否尝试发送逃生钥匙?这将有助于解决您的问题。不帮助webdriver.ActionChains(驱动程序)。发送密钥(keys.ESCAPE)。执行()锁定!谢谢你
function clipboard(format, data) {
    const tmp = document.oncopy;

    document.oncopy = function clipboard_oncopy(e) {
        e.clipboardData.setData(format, data);
        e.preventDefault();
    };
    document.execCommand("copy", false, null);
    alert("Copied to Clipboard");

    document.oncopy = tmp;
}