2

enter image description here

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;
}
2
  • Did you try sending the Escape key? This topic would be helpfull in resolving your issue. Commented Mar 13, 2018 at 14:08
  • Doesnt help webdriver.ActionChains(driver).send_keys(Keys.ESCAPE).perform() Commented Mar 13, 2018 at 14:18

1 Answer 1

4

Try this:

driver.switch_to_alert().accept()

Sign up to request clarification or add additional context in comments.

1 Comment

Nailed! Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.