"How to solve Selenium Webdriver path error ?" - selenium-webdriver

I stored it in d Drive and gave loction of webdriver but it gives an error
from selenium import webdriver
chrome_driver_path = "D:\chromedriver.exe"
url = "https://www.linkedin.com/jobs/search/?f_LF=f_AL&geoId=102257491&keywords=python%20developer&location=London%2C%20England%2C%20United%20Kingdom&redirect=false&position=1&pageNum=0"
driver = webdriver.Chrome(executable_path=chrome_driver_path)
driver.get("url")

you should try this: driver.get(url)
not this: driver.get("url")

Related

selenium c# edge browser : 'Unexpected error. Unknown error'

OS Build Number:- 18363.900
Edge Version: 83.0.478.54
MicrosoftWebDriver Version: 83.0.478.54
Here is the code:
System.Environment.SetEnvironmentVariable("webdriver.edge.driver", "E:\\edgedriver_win64\\msedgedriver.exe");
IWebDriver driver = new EdgeDriver();
I am getting error as: OpenQA.Selenium.WebDriverException: 'Unexpected error. Unknown error'
Which version of Selenium WebDriver are you using? I suggest you to use the latest version 4.0.0-alpha05 and use the code below:
EdgeOptions edgeOptions = new EdgeOptions();
edgeOptions.UseChromium = true;
edgeOptions.BinaryLocation = #"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe";
var msedgedriverDir = #"D:\webdriver83.0.478.54";
var driver = new EdgeDriver(msedgedriverDir, edgeOptions);
driver.Navigate().GoToUrl("https://bing.com");
Thread.Sleep(3000);
driver.Close();
Note: Change the paths in the code to your owns.
Result:

Use Selenium chrome and gecko driver as the same time

Is there a way to fire off the use of the chrome and gecko webdriver at the same time without duplicating code?
Right now I'm swapping between the two.
from selenium import webdriver
from selenium.common.exceptions import
def setUp(self):
# self.browser = webdriver.Firefox()
self.browser = webdriver.Chrome()
Yes, you can do it. However there must be some place where you specify the browser to be opened.
Browser name to be opened can be passed as an argument to setup method
from selenium import webdriver
def setUp(self, browserName):
if browserName == "Firefox":
self.browser = webdriver.Firefox()
elif browserName == "Chrome" :
self.browser = webdriver.Chrome()
Browser name to be opened can be read from some configuration/properties file.
from selenium import webdriver
def setUp(self):
browserName = #Code to read value from configuration file
if browserName == "Firefox":
self.browser = webdriver.Firefox()
elif browserName == "Chrome" :
self.browser = webdriver.Chrome()
You haven't specified the environment, so I'll go with this. This is how it could be done in Katalon Studio:
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import com.kms.katalon.core.webui.driver.DriverFactory
System.setProperty("webdriver.chrome.driver", DriverFactory.getChromeDriverPath())
WebDriver driver1 = new ChromeDriver()
WebDriver driver2 = new FirefoxDriver()
DriverFactory.changeWebDriver(driver1)
// test with Chrome
DriverFactory.changeWebDriver(driver2)
// test with Firefox

Hiding the CMD window of PhantomJS on python with selenium

I am trying to hide the CMD window that appears when launching PhantomJS with python:
from selenium import webdriver
browser = webdriver.PhantomJS()
There appears to be a solution when working with C#, however, I was not able to find anything similar for python. Since the feature for C# was added back in 2014, I assume something similar should exist for python too.
I'm using latest PhantomJS and Python 3.6.2.
This is how it looks like:
For me,
The below code works fine.
driver = webdriver.PhantomJS(
service_args=service_args,
desired_capabilities=caps,
executable_path='phantomjs.exe',
service_log_path=None
)
Here you have to add service_log_path=None for no log file that's why the console window will get hidden.
Still Not solved then
replace code from
(C:\Users\YOUR_USER_NAME\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\selenium\webdriver\common\service.py) file
self.process = subprocess.Popen(cmd, env=self.env, close_fds=platform.system() != 'Windows', stdout=self.log_file, stderr=self.log_file, stdin=PIPE)
to
self.process = subprocess.Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=False, creationflags=0x08000000)

Open firefox browser using Selenium 3.5.2 , Python3.6

I had installed python 3.6 and selenium 3.5.2 version,geckodriver.exe . But when i used below code not able to open fire fox
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
driver=webdriver.Firefox("C:\\Users\\Desktop\\Selenium\\seleniumfirefoxdriver\\geckodriver.exe")
driver.set_page_load_timeout(20)
driver.get("www.google.com")`enter code here`
driver.maximize_window()
driver.implicitly_wait(20)
Error shown as
NotADirectory Error:
[Win Error 267] The directory name is invalid: C:\\Users\\Desktop\\Selenium\\selenium firefoxdriver\\geckodriver.exe
Try below code-
driver = webdriver.Firefox(executable_path=r'C:\Users\Desktop\Selenium\seleniumfirefoxdriver\geckodriver.exe')
If there is a space in folder name 'selenium firefoxdriver', rename that folder to 'seleniumfirefoxdriver'
Try single slash and folder name doesn't contain space either use _ or remove space in folder name "selenium firefoxdriver". Make it "selenium_firefoxdriver" or "SeleniumFirefoxdriver".
and then use this code:
driver = webdriver.Firefox(executable_path=r'C:/Users/Desktop/Selenium/selenium_firefoxdriver/geckodriver.exe')
or
driver = webdriver.Firefox(executable_path=r'C:/Users/Desktop/Selenium/SeleniumFirefoxdriver/geckodriver.exe')

Selenium 3.0.1, gekodriver v0.11.1, firefox 49.0.2 "Unable to connect to host 127.0.0.1 on port 7055" exception

Trying to upgrade to Selenium 3.0 from Selenium 2.53. I can not put firefox in path, nor can put the gekodriver in path. I was using this in Selenium 2:
String firefoxLocation = System.getenv("ProgramFiles(X86)") + "\\Mozilla Firefox_42\\firefox.exe";
System.setProperty("webdriver.firefox.bin", firefoxLocation);
driver = new FirefoxDriver();
This worked perfectly. I upgraded to Selenium 3.0, installed firefox 49 and downloaded the latest geko. I now have this:
String firefoxLocation = System.getenv("ProgramFiles(X86)") + "\\Mozilla Firefox_49\\firefox.exe";
String gekoLocation = "..\\common\\geko\\gekodriver.exe";
System.setProperty("webdriver.firefox.bin", firefoxLocation);
System.setProperty("webdriver.firefox.marionette", gekoLocation);
driver = new FirefoxDriver();
Firefox opens to a blank window, then times out. I tried instead of setting webdriver.firefox.marionette, setting webdriver.geko.driver, but got the error that I must use "webdriver.geko.driver" (which I was using). How do I arrange it so I can specify a different firefox.exe location and a different gekodriver.exe location?
spelling wrong.
try this:
System.setProperty("webdriver.gecko.driver", gekoLocation);
use gecko instead of geko

Resources