Task scheduler is not running Selenium scripts - python

I am working with Selenium Webdriver using Python. I can navigate and do stuff normally when I run it through IDLE.
And also it works perfectly when I run it by task scheduler "Run with user logged on" but only manually if I make it run. If the system is locked, it stops near the SEND_KEYS function.
Attached the code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
import time
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.select import Select
import os
import win32com.client as win32
driver=webdriver.Chrome()#chrome_options=options
driver.maximize_window()
window_before = driver.window_handles[0]
try:
driver.get('https://itsm.windstream.com/')
time.sleep(20)
#WebDriverWait(driver,60)
#pythoncom.CoInitialize()
driver.switch_to_window(window_before)
aw=True
while aw:
shell = win32.Dispatch("WScript.Shell")
shell.Sendkeys('My_ID')
shell.Sendkeys('{TAB}')
shell.Sendkeys('My_password')
shell.Sendkeys('{ENTER}')
aw=False
except Exception as e:
print (e)
It wont work directly, so I'm opening Chrome by local host and opening this file to run instead of batch file, which doesn't make any difference
.

Try the schedule library for this, it worked for me sir.
import schedule
def start():
print("{} Start the job".format(datetime.datetime.now()))
schedule.every().day.at("09:00").do(start)

Related

How interact with dcc.DatePickerSingle using selenium

I am testing a dashboard created with dash and I have a couple of dcc.DatePickerSingle. I want to test these by introducing some dates and then also test that the result generated by the dashboard is equal to the expected value.
I show the code I am using
import pytest
from selenium.webdriver import Chrome
from selenium.webdriver.common.keys import Keys
import pytest
from selenium import webdriver
import sys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from time import sleep
URL = 'http://127.0.0.1:8001/'
#pytest.fixture
def browser():
# Initialize ChromeDriver
driver = Chrome("./chromedriver")
# Wait implicitly for elements to be ready before attempting interactions
driver.implicitly_wait(10)
# Return the driver object at the end of setup
yield driver
# For cleanup, quit the driver
driver.quit()
def test_dates(browser):
browser.get(URL)
data_start ="Hola"
search_input1 = browser.find_element_by_id('my-date-picker-start')
search_input1.send_keys(data_start)
The error I got after many different attend is
ElementNotInteractableException
To run this the command is pipenv run python -m pytest
Is this element not iterable (I douth that) or I am doing something wrong (Very likely)?
You should use explicit wait rather than implicit wait.
So, remove driver.implicitly_wait(10) (and never use it until you are clearly understand how implicit wait works) and try this:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
search_input1 = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.ID, "my-date-picker-start")))
search_input1.send_keys(data_start)

Python Selenium Edgedriver stuck on showing "data;," in the address bar, not opening web page

I had this issue on 2 different systems, on first PC it went away after a reboot, on the other it had not gone away
Below is a portion of the code in question:
I masked some things on purpose
The edge browser is stuck on openign page with data;, shown in the address bar. It does not go beyond this.
I checked that Edge and Edgedriver are the same exact version, if it matters.
I cannot use Chrome or any other drivers for this project
Why doesn't selenium advance past the opening of the program?
I also have an error in CMD when it launches: [9704:11992:0305/080544.278:ERROR:storage_reserve.cc(164)] Failed to open file to mark as storage reserve: C:\Users**\AppData\Local\Temp\scoped_dir3468_1483298328\Default\Code Cache\js on selenium
How do I fix this?
# importing required package of webdriver
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from time import sleep
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.opera.options import Options
from selenium.webdriver.support.wait import WebDriverWait
import schedule
import time
from random import randint
def job():
while True:
# Instantiate the webdriver with the executable location of MS Edge
browser = webdriver.Edge(r"C:\Users\*****\Desktop\msedgedriver.exe")
sleep(2)
browser.maximize_window()
sleep(2)
browser.get('https://********/) #masked the name of website on purpose
try:
# Get the text box to insert Email using selector ID
myElem_1 = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.ID, 'anti-myhub')))
sleep(3)
# Entering the email address
myElem_1.click()

Selenium webdriver stops with no error-message when navigating through paypal login

I'm trying to log into paypal.com and make a payment automatically.
The program successfully loads the login page(https://www.paypal.com/us/signin) and inputs the email, but when I click the next button the web driver unexpectedly closes without generating an error message.
Has anyone encountered this issue before? Could it be because the next button is a disguised captcha, to keep robots from logging in?
I have already tried using time.sleep(3) to give the page time to load. I can't see any other issues with the code.
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.keys import Keys
def paypal_pay(): # pass in user address
driver = webdriver.Chrome()
timeout = 20
paypal = "https://www.paypal.com/us/signin"
driver.get(paypal)
email = "emailstuff#gmail.com"
emailElement = driver.find_element_by_id('email')
print(emailElement)
emailElement.send_keys(email)
time.sleep(3)
nextElement = driver.find_element_by_id('btnNext').click()
def main():
paypal_pay()
main()
Your code is working fine but the way that you have implemented is causing the problem, I mean you are using the main() method and what it will do is, once this method gets called and executed, it will close all the connections at end. Hence the reason your browser also getting closed without any error because your code is working fine till there:
Try the below modified code without main method which works completely fine :
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome("chromedriver.exe");
paypal = "https://www.paypal.com/us/signin"
driver.get(paypal)
email = "hello#gmail.com"
emailElement = driver.find_element_by_id('email')
print(emailElement)
emailElement.send_keys(email)
time.sleep(3)
nextElement = driver.find_element_by_id('btnNext').click()
print("=> Done...")
For more info on main(), refer this link
I hope it helps...
When I run your code After click on next button the Chrome browser crashes and in console i can see the following error.
<selenium.webdriver.remote.webelement.WebElement (session="577ff51b46a27eefeda43ccd320db48b", element="0.571535141628553-1")>
That means you need to start a RemoteWebDriver instead of ChromeDriver.
Step 1: Download the Selenium Standalone Server from following link
https://www.seleniumhq.org/download/
Step 2: open command prompt as an administrator go to the downloaded path and type the below command and press enter
java -jar selenium-server-standalone-3.141.59.jar
Step 3: To verify Hub is running, open a browser and type the below url.Default port of hub is 4444
http://localhost:4444/grid/console
Step 4: Use the following code.If you follow above steps properly it should work perfectly the below code.
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
def paypal_pay(): # pass in user address
desired_caps = DesiredCapabilities.CHROME
grid_url = "http://localhost:4444/wd/hub"
driver = webdriver.Remote(desired_capabilities=desired_caps, command_executor=grid_url)
paypal = "https://www.paypal.com/us/signin"
driver.get(paypal)
email = "emailstuff#gmail.com"
emailElement = driver.find_element_by_id('email')
print(emailElement)
emailElement.send_keys(email)
nextElement = driver.find_element_by_id('btnNext')
nextElement.click()
def main():
paypal_pay()
main()
Please let me know if this work for you.Good Luck.

Chrome webdriver is not sending keys to pop up

I am using the below code.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
import time
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.select import Select
import os
import win32com.client as win32
driver=webdriver.Chrome()
driver.maximize_window()
driver.get('https://itsm.windstream.com/')
shell = win32.Dispatch("WScript.Shell")
time.sleep(5)
shell.Sendkeys('My_id')
shell.Sendkeys('{TAB}')
shell.Sendkeys('My_password')
shell.Sendkeys('{ENTER}')
Once i open the link, Chrome will pop up asking the id and password.
I am using shell and it was working previously.
Now this is not working.
Getting console output as (chrome Console)
text.cc Not Implemented
In python shell, No errors shows up.
Please assist.
Thanks.
I tried everything available in stack over flow and it doenst work
I solved this by adding a new line.
window_before = driver.window_handles[0]
driver.switch_to_window(window_before)
Even though the driver is in the current frame, the new update of chrome driver doesn't recognize. After switching to current window, the code works.
Thanks for helping.
If it's kind of alert type, you can use Alert objects
alert = driver.switchTo().alert()
alert = wait.until(alertIsPresent())
and then
alert.getText()
alert.sendKeys()
aler.accept()
alert.dismiss()
Try to pass authentication while you get the url, something like this
driver.get('http://admin:admin#itsm.windstream.com');

How to configure selenium RC, Web driver in ubuntu

I have an ubuntu server and the script that will open particular website(firefox) and perform some operations and closes.
But always I used to get this error
selenium.common.exceptions.ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with stacktrace fxdriver.preconditions.visible...
Here is some of my code
import time
import sys
import json
from selenium import webdriver
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.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from pyvirtualdisplay import Display
from xvfbwrapper import Xvfb
......
......
display = Display(visible=0, size=(1300, 1000))
display.start()
# Initiate the browser
binary = FirefoxBinary('/usr/bin/firefox')
browser = webdriver.Firefox(firefox_binary=binary)
browser.get('http://somesite.com/')
Now When I try to find some element after this getting the above error. Even though added sleep for 30s no use. Can anyone guess whats wrong with this?

Categories

Resources