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');
Related
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
import time
browser=webdriver.Chrome('C:/Users/Dell/Downloads/chromedriver')
browser.get('https://www.screener.in/')
sbox = browser.switch_to.active_element
sbox.send_keys('Infosys Ltd')
sbox.send_keys(Keys.RETURN)
The enter key is not working. I have tried using .submit() too but still isn't working. Please let me know if there is any other way to get it.
Try using Keys.ENTER instead of Keys.RETURN
url = "https://www.foodpanda.pk/restaurants/new?lat=24.9414896&lng=67.1676002&vertical=restaurants"
browser = webdriver.Chrome()
browser.get('https://www.screener.in/')
sbox = browser.switch_to.active_element
sbox.send_keys('Infosys Ltd')
WebDriverWait(browser, 10).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, '[class="dropdown-content visible"]')))
sbox.send_keys(Keys.ENTER)
wait for the dropdown to be visible before sending the enter
imports required:
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
switch_to may be unstable depending on browsers. Also, make sure sbox is visible before you interact with it. Try:
sbox['value'].send_keys('Infosys Ltd')
sbox['value'].send_keys(Keys.RETURN)
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()
I try to set up a test for a webpage using Selenium WebDriver and Python. Therefore I start the Docker image selenium/standalone-firefox.
Within this test normally a JavaScript written prompt pops up and want to receive an entry prior I can click OK.
But how can I interact with this prompt and the OK button?
On Selenium IDE the recorder uses answer on next prompt for that. How to do this with Python-Selenium? If Python does not support an corresponding command, how do I get the needed information to do the same with the available commands?
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
from selenium.webdriver.firefox.options import Options
# connect to docker Selenium Server
options = Options()
driver = webdriver.Remote(
command_executor='http://localhost:4444/wd/hub',
desired_capabilities=options.to_capabilities()
)
driver.get("https://www.ecalc.ch/motorcalc.php?hacker&lang=en&weight=4500&calc=auw&motornumber=1&warea=60&elevation=300&airtemp=25&motor=hacker&type=2|a60-7xs_v4_28-pole&gear=1&propeller=apc_electric&diameter=18&pitch=10.0&blades=2&batteries=topfuel_light_4500mah_-_30/45c&s=8&esc=master_spin_160_pro&cooling=good")
print(driver.title)
driver.find_element_by_id("modalConfirmOk").click()
driver.find_element_by_name("btnCalculate").click()
driver.find_element_by_id("AddCSV").click()
????
You must handle the prompt alert. Try it with:
driver.switchTo().alert().sendKeys("Your project name");
You can handle using alert class in selenium.
#Switch the control to the Alert window
obj = driver.switch_to.alert
time.sleep(2)
#Enter text into the Alert using send_keys()
obj.send_keys('test')
refer this link selenium
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.
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)