[英]how to close chrome browser popup dialog using selenium webdriver and python
[英]How to close yet another chrome popup using python selenium
这是我的代码:
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
这是(自动查看)扩展名的来源,我认为这段代码会生成此弹出窗口
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.