简体   繁体   中英

How to close yet another chrome popup using python selenium

在此处输入图片说明

Link to "chrome_options.add_extension(r'C:\\Users\\Administrator\\Desktop\\chromedriver_win32\\extension.crx')"

Here is my code:

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)   

i tried this code, but it didn't helps

driver.switchTo().alert().accept();

this code don't work too

driver.send_keys("Enter")

if i right-click on popup there is simply no action, so i cant find XPath, class id

this is sources that (autoview) extension, i assume that this code generate this popup

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;
}

尝试这个:

driver.switch_to_alert().accept()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM