Website opened selenium just stop working - python

Website opened in selenium just stops working after a few seconds but rest of the code works without problem , I tried opening the site in opera as well in chrome but with the same result when I tried to open shorter version of this program in basic Ide it worked without a problem but when I tried to run this version in pycharm it again didnt worked
Code:
from selenium import webdriver
def web(): driver = webdriver.Opera() driver.get('website') web()

Related

Why does my code running Selenium run correctly on repl.it but not on my Ubuntu VM?

I have a simple code that uses Selenium to download a dynamically rendered webpage.
from selenium import webdriver
Chrome_options = webdriver.ChromeOptions()
Chrome_options.add_argument('--no-sandbox')
Chrome_options.add_argument('--headless')
Chrome_options.add_argument('--disable-gpu')
Browser = webdriver.Chrome(options=Chrome_options)
Browser.get('https://example.com/hello')
Data = Browser.page_source
with open("webpage.html","w") as fout:
fout.write(Data)
This runs correctly on repl.it, i.e. it downloads what is dynamically rendered, like a "Save As" on a browser.
However, when I run the same code in my Ubuntu 20.04 VM, I only got the static HTML page as if I'm running wget or "View Page Source".
I'm using Python 3.8 and Selenium 3.141.0 on both repl.it and VM, and my VM is running Chrome and ChromeDriver 92.0.4515.
Why does the same code not run correctly on my VM?
ETA: I noticed that repl.it took longer to complete Browser.get, while my VM completed it very quickly. Could it be for some reason, my VM did not wait for everything to finish loading?
Just realized I needed to give the page some time to load. Seems like repl.it waits for the page to finish loading, but I needed to include a time.sleep(10) in my script on the VM so the page finishes loading.

Chrome crashes when opened with selenium webdriver

When I am launching Chrome browser from python shell using Selenium webdriver, it works well and good. But, when I launch the browser using the same code from inside a Python script, it crashes. How can I solve it?
Okay got it.
The reason was that I was not providing a url after opening the broswer.
We need to provide the url after opening the browser so that it can go to a specific page and it works fine, else it will crash.

key_down & key_up commands in Selenium Webdriver (Python) suddenly won't work

I have been using Chrome Webdriver along with Selenium/Python to load and save some webpages. It had been working fine. Today Chrome kept crashing as soon as it opened so I downloaded the latest Chrome Webdriver which solved that issue.
However, the following lines did not seem to work any more:
actions = ActionChains(driver)
actions.key_down(Keys.CONTROL).send_keys('s').key_up(Keys.CONTROL).perform()
There was no error returned in the command prompt and all the other keyboard commands that did not use key_down/key_up worked correctly.
I have googled for a while but can't figure out why it is not working any more. Thanks

Python-Selenium test script not working

I am trying to automation some action on a website using Python and Selenium, this is the sample code I am trying to run, from the Mozilla website for running the Firefox webdriver
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
caps = DesiredCapabilities.FIREFOX
caps["marionette"] = True
caps["binary"] = "/usr/bin/firefox-aurora"
driver = webdriver.Firefox(capabilities=caps)
driver.get("https://www.google.com")
driver.quit()
When running this code, the Firefox instance opens normally, and I can even use the instance as if I just opened Firefox normally, but the code 'stops' executing at the driver = webdriver.Firefox(capabilities=caps) line, I tried debugging the code with no luck, the whole execution seems to just stop at this line, and nothing after it is reached!
I am running Python3.5, Selenium version 2.53.6, I have the 'Wires' executable at the /usr/local/bin which is in the environment's PATH, I also have Firefox Aurora version 49.0a2 running on ArchLinux.
Thanks in advance.
[Update:]
I managed to get it to work after all using Firefox 46 (the normal version).

Selenium Python script

I am running following code in PyCharm
from selenium import webdriver
driver = webdriver.Firefox
Scripts executes successfully with following message in console
C:\Python34\python.exe C:/Users/dev/PycharmProjects/PYLearn/firs_selenium_script.py
Process finished with exit code 0
But Firefox Browser is not opening, I have selenium installed using pip, Do I need additional setting to make this work.
Thanks,
To launch the browser your code should look like:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://your-url')
After the test you will want the close the browser, so add:
self.browser.quit()
Hope this solve your problem.
More info: http://selenium-python.readthedocs.org/getting-started.html
Go to Python Console at the bottom and run your commands and check the error
You can try this:
from selenium import webdriver
browser = webdriver.Chrome()
Browser should be opened , anyways check whether the browser started running or not.
Once, your browser fully loaded, your command will move to next line

Categories

Resources