Selenium opening Brave, but not going to URL. Using Python - python

Yes, yes, I know everyone is going to be angry at me for asking this question again. But I have looked at every question (related to Brave, Selenium, Python and Linux) in Stack Overflow, but nothing has worked for me. Here is my problem: I run the code. No errors. Brave opens up and says it is being controlled by “automated test software” (good sign). But then it doesn't go to the URL I want it to go to. I have checked the chromedriver and Chromium version, they match. I also use Ubuntu 20.04 LTS. Last thing, I installed Brave using snap.
Here is my code:
from selenium import webdriver
brave_path = "/snap/bin/brave"
option = webdriver.ChromeOptions()
option.binary_location = brave_path
driver = webdriver.Chrome("/bin/chromedriver_linux64/chromedriver", options=option)
driver.get("https://youtube.com/")

Related

Selenium Opens Browser But Refuses to Execute the Next Line of Code

It looks like after opening the browser, Selenium cannot move on for some reasons I can't figure out. No error was ever displayed.
Here is my simple code:
import selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
# Using Chrome to access web
browser = webdriver.Chrome(executable_path = "C:\Program Files\Google\Chrome\Application\chrome.exe")
print ("done")
# Open YouTube website
browser.get("https://www.youtube.com/")
The browser opens just fine, but the print("done") statement is never executed. (In the terminal the word "done" was never printed. So, it infers that the selenium has never finished executing the command to open the browser even though the browser has opened, and I have waited for several minutes.
Thanks in advance to our wonderful StackOverflow community!
The reason is because you are using chrome.exe which is for browser. Instead you should download chromdriver.exe, Please download from here. You should download Latest stable release: ChromeDriver 94.0.4606.61 (as on 3rd-oct-2021). Keep that in your automation directory and any directory of your preference.
driver_path = r'C:\\Users\\username\\Desktop\\Automation\\chromedriver.exe'
driver = webdriver.Chrome(executable_path = driver_path)
Note that, in place of driver_path, you should give the path where you've kept the chromdriver.exe
You should use chromedriver.exe instead of the path to your chrome.exe.
Download the chromedriver suitable for your chrome version, from here:
donwload Chromedriver.exe
Afterwards, do something like this:
browser = webdriver.Chrome("E:\YourPathToChromeDriver\chromedriver.exe")
Try these steps:
Check your Google Chrome version here "chrome://settings/help"
Download chromedriver.exe from "https://chromedriver.chromium.org/downloads"
Change executable path to newly downloaded file.
As mentioned above, this issue is the chrome.exe. You need to use a chromedriver instead. You can download one manually here https://chromedriver.chromium.org/downloads and then set the path to it like you did to the chrome.exe.
However, instead of downloading the chromedriver manually, I recommend using a library on GitHub which does that for you and loads it from cache if there is already one installed. (I'm not the owner nor the maintainer of this repository, but I do find it rather simple to use.)
https://github.com/SergeyPirogov/webdriver_manager
First you'd need to pip install webdriver-manager and then you can use it as following:
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())

Different selenium behaviour on Python

Dear Python community,
I did a small scrip on Python 3 with Selenium to automatize some basic tasks online. It worked fine. It opened the firefox browser, logged in on a web, type text on a search field, etc. Nothing too fancy.
I am still learning and trying different things so in the meantime I installed anaconda, python 2.7, and updated python 3 form 3.4 (I think) to 3.6. I messed something up with all this.
Now my script doesn't work anymore...
First it complaint that the geckodriver was not found. I am sure I didn't installed the first time. Anyway I downloaded it and put it on a Path enviroment varible.
Script then runs but doesn't stop were it did before. It does not wait for the page to load. If I don't want it to fail I have to use the explicit/implicit wait on selenium.
I have problems as well when finding elements on the web using browser.find_element_by_partial_link_text that when I wrote the script worked well.
def download(serial,apoc_user,apoc_pass):
shutil.rmtree(aux.download_path, ignore_errors=True)
profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.folderList', 2) # custom location
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.download.dir', aux.absolut_path + aux.download_path)
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', aux.all_types_of_files)
browser = webdriver.Firefox(firefox_profile=profile)
browser.get("https://some.web.com")
elem = browser.find_element_by_id('username')
elem.send_keys(user)
passElem = browser.find_element_by_id('password')
passElem.send_keys(password)
browser.find_element_by_id('loginBtn').click()
elem = browser.find_element_by_id('Asset')
elem.send_keys(serial)
elem.submit()
Before twinkering my code, does someone know what is going now?
I currently have python 3.6 and selenium 3.0.0. I tried with python 3.5 and selenium 3.0.2 without success.
I code with Pycharm Community Edition running on windows 7.
Any help will be welcomed!
Thank you all.

Selenium Chromedriver launches Chrome, but doesn't open website (new Chromedriver, same old issue)

I am having trouble using Selenium Chromedriver on Windows 7. To display the problem, I've boiled it down to a simple script to simply launch the New York Times website:
from selenium import webdriver
# --LOCATIONS --
# The Chrome app:
# C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
# The Chrome binary:
# C:\Python27\Scripts\chromedriver.exe
chromedriver_path = "C:\Python27\Scripts\chromedriver.exe"
driver = webdriver.Chrome(executable_path=chromedriver_path)
driver.get('https://www.nytimes.com/')
The Chrome Browser launches (leading me to speculate that there's nothing with the Chrome application path), but rather than going to the NYT website, the following happens:
The string data:, appears in the URL address bar, and 2 alert notifications come up: one that says "You are using an unsupported command-line flag: --ignore-certificate-errors. Stability and security will suffer." and another that says "Disable developer mode extensions: Extensions running in developer mode can harm your computer. If you're not a developer, you should disable these extensions running in developer mode to stay safe."
This didn't happen when I used Selenium for Firefox- so I'm not sure what to do with Chrome. I've tried looking this issue up on the internet beforehand, but all the issues/solutions are dated from a few years back (2014-2015), and I believe the Selenium packages and Chromedriver binaries have been updated since then.
Does anyone know how I can get my code working? Thank you in advance.
I'd have to see your computer to examine how Chromedriver is installed, but as that's not quite feasible, I would at least recommend uninstalling any chromedriver executables on your computer and then downloading it into your project's directory.
It's really just an IT rule-of-thumb; if you've ruled out every other issue that you're aware of, then there's a good chance the problem is something you're not recognizing. Start at square 1 and reinstall Chromedriver.
You can disable Developer mode extension by following code(java)
ChromeOptions options = new ChromeOptions();
options.addArguments("chrome.switches","--disable-extensions");
System.setProperty("webdriver.chrome.driver","F:\\Stuff\\Jars\\chromedriver.exe");
driver = new ChromeDriver(options);
driver.manage().window().maximize();
driver.get("https://www.nytimes.com/");

Setting default download directory Selenium ChromeDriver

I see this question has been answered several times before but none of the solutions appear to be working anymore.
My script looks like:
from selenium import webdriver
chromeoptions = webdriver.ChromeOptions()
prefs = {"download.default_directory" : "/root/path/to/folder"}
chromeoptions.add_experimental_option("prefs",prefs)
browser = webdriver.Chrome(chrome_options=chromeoptions)
Everything is working as normal...but the download directory reset fails silently.
I have tested the rest of the code (but not the download directory reset) on Windows and it is working correctly, other similar scripts (without the download) are working normally too. The chromeoptions object is also correctly showing the target directory under experimental options...so it is presumably being passed to the browser object.
Something is going wrong, I am not sure what? I am using Python 2.7, latest versions of Chrome/Selenium/ChromeDriver on Ubuntu 14.

Python test using selenium cannot perform simple test

I am trying to learn about Selenium but I am not able to get even a simple program to test. Selenium webdriver seems to not be cooperating with Firefox and I am very frustrated, so I come to Stack Overflow for help.
For background, I use Python, can install with pip, and know command line.
I am on windows 10, firefox 48, and selenium webdriver 3 with python 3.5.2
Whenever I run the selenium test, (it opens a Firefox windows and the selenium website)
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://www.seleniumhq.org')
I always get an error:
selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: C:\ ... \AppData\Local\Temp\tmp68m5rtwt If you specified a log_file in the FirefoxBinary constructor, check it for details
It also opens a firefox window and has the link of about:blank&utm_content=firstrun(not a valid url)
I have looked across the internet for a similar situation, but nothing really close. I also tried many tutorials and made sure that I installed selenium the right way. I noticed that firefox was recently updated, but I am not sure if this has any effect.
I would appreciate any help for this, and instructions for what I should do.
Firefox 48+ doesn't support webdriver.Firefox().
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
caps = DesiredCapabilities.FIREFOX
caps["marionette"] = True
caps["binary"] = "path/to/your/firefox"
browser = webdriver.Firefox(capabilities=caps)
browser.get('http://www.seleniumhq.org')
This is what I was trying
1. download geckodriver.https://github.com/mozilla/geckodriver/releases. v.0.10.0is for selenium 3(beta).
2. add PATH your geckodriver.
4. rename it to wires
5. restart shell
6. check the version
$ wires --version
7. and run above the code.

Categories

Resources