0

I have a problem with Selenium(Python). Does Somebody know a solution?

THE PROBLEM If I run a new Script the browser opens and runs an old script, then closes and opens again, and then runs the new script.

WHAT I TRIED

  • I already deleted the cookies of my browser(but only the ones from my browser and not the automated one that opens).
  • I already deleted the python file which is running before the new script

The code i tried for clearing the chache in the automated browser, but also not worked.... it is still running the a older selenium browser session, before starting the new sessions code.

from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from Selenium import webdriver
import time
driver = webdriver.Chrome(executable_path="C:\Program Files (x86)\chromedriver.exe")

def delete_cache():
    driver.execute_script("window.open('');")
    time.sleep(2)
    driver.switch_to.window(driver.window_handles[-1])
    time.sleep(2)
    driver.get('chrome://settings/clearBrowserData') # for old chromedriver versions use cleardriverData
    time.sleep(2)
    actions = ActionChains(driver)
    actions.send_keys(Keys.TAB * 3 + Keys.DOWN * 3) # send right combination
    actions.perform()
    time.sleep(2)
    actions = ActionChains(driver)
    actions.send_keys(Keys.TAB * 4 + Keys.ENTER) # confirm
    actions.perform()
    time.sleep(5) # wait some time to finish
    driver.close() # close this tab
    driver.switch_to.window(driver.window_handles[0]) # switch back
delete_cache()

The code i run, this will be an Email Automation. But the Problem is, that before that scrip can start selium always runs and old script, then finishes it and close the browser, than open a new browser and starts this code.

import XLUtilitis
from Selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys


driver = webdriver.Chrome(executable_path="C:\Program Files (x86)\chromedriver.exe")

#Webmail registration
driver.get("https:***MY Email Program")
search = driver.find_element_by_xpath("//*[@id='io-ox-login-username']")
search.send_keys("***My Email")
search = driver.find_element_by_xpath("//*[@id='io-ox-login-password']")
search.send_keys("***My Password")
time.sleep(2)
search = driver.find_element_by_xpath("//*[@id='io-ox-login-button']").click()
time.sleep(2)

#Send Email
driver.find_element_by_xpath("//*[@id='window-0']/div/div[4]/div[1]/ul/li[1]/a").click()
time.sleep(4)
4
  • 1
    Which command are you use? What other information about your context can you give? – João Farias Apr 5 at 7:29
  • Can you debug and trace it through? – Vishal Aggarwal Apr 6 at 8:48
  • @João Farias i posted the code that i tried and what i am currently useing. i hope it helps – ChrisAGO Apr 17 at 21:30
  • @Vishal Aggarwal how do you mean debugging? I tried it in pycharm but there is no notice that someting is not in order – ChrisAGO Apr 17 at 21:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.