Open firefox browser using Selenium 3.5.2 , Python3.6 - selenium-webdriver

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')

Related

Setup Xdebug for Shopware docker failed

I try to setup Xdebug for shopware-docker without success.
VHOST_[FOLDER_NAME_UPPER_CASE]_IMAGE=ghcr.io/shyim/shopware-docker/6/nginx:php74-xdebug
After replacing your Folder Name and running swdc up Xdebug should be activated.
Which folder name should I place?
Using myname, the same name as in /var/www/html/myname, return error on swdc up myname:
swdc up myname
[+] Running 2/0
⠿ Network shopware-docker_default Created 0.0s
⠿ Container shopware-docker-mysql-1 Created 0.0s
[+] Running 1/1
⠿ Container shopware-docker-mysql-1 Started 0.3s
.database ready!
[+] Running 0/1
⠿ app_myname Error 1.7s
Error response from daemon: manifest unknown
EDIT #1
With this setup VHOST_MYNAME_IMAGE=ghcr.io/shyim/shopware-docker/6/nginx:php81-xdebug (versioned Xdebug) the app started:
// $HOME/.config/swdc/env
...
VHOST_MYNAME_IMAGE=ghcr.io/shyim/shopware-docker/6/nginx:php81-xdebug
But set a debug breakpoint (e.g. in index.php), nothing happens
EDIT #2
As #Alex recommend, i place xdebug_break() inside my code and it works.
Stopping on the breakpoint the debugger log aswers with hints/warnings like described in the manual:
...
Cannot find a local copy of the file on server /var/www/html/%my_path%
Local path is //var/www/html/%my_path%
...
click on Click to set up path mapping to open the modal
click inside modal select input Use path mapping (...)
input field File path in project response with undefined
But i have already set up the mapping like described in the manual, go to File | Settings | PHP | Servers:
Why does not work my mapping? Where failed my set up?
The path mapping needs to be between your local project path on your workstation and the path inside the docker containers. Without xDebug has a hard time mapping the breakpoints from PHPStorm to the actual code inside the container.
If mapping the path correctly does not work and if its a possibility for you, i can highly recommend switching to http://devenv.sh for your development enviroment. Shopware itself promotes this new enviroment in their documentation: https://developer.shopware.com/docs/guides/installation/devenv and provides an example on how to enable xdebug:
# devenv.local.nix File
{ pkgs, config, lib, ... }:
{
languages.php.package = pkgs.php.buildEnv {
extensions = { all, enabled }: with all; enabled ++ [ amqp redis blackfire grpc xdebug ];
extraConfig = ''
# Copy the config from devenv.nix and append the XDebug config
# [...]
xdebug.mode=debug
xdebug.discover_client_host=1
xdebug.client_host=127.0.0.1
'';
};
}
A correct path mapping should not be needed here, as your local file location is the same for XDebug and your PHPStorm.

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)

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

browser.get(URL) does not work

I am having an issue with entering text into the address bar nothing happens and I get the error
selenium.common.exceptions.WebDriverException: Message: Can't load the
profile. Profile Dir:
/var/folders/8_/f48lnzrs7r59_h2yb3dkfbh40000gn/T/tmpsGffLD If you
specified a log_file in the FirefoxBinary constructor, check it for
details.
I am able to open the browser but when I uncomment the code browser.get('http://www.google.com') nothing happens and I get the error listed above. I am using Firefox 48, Python 2.7.10 and selenium-2.53.6-py2.7.egg
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://www.google.com')
Change that line to
browser.url('http://www.google.com')
OR
browser.open('http://www.google.com')

Using PhantomJS through Selenium with Python - WebDriverException error

I am using the following code, as recommended here: Is there a way to use PhantomJS in Python?.
from selenium import webdriver
driver = webdriver.PhantomJS()
driver.set_window_size(1024, 768) # optional
driver.get('https://google.com/')
driver.save_screenshot('screen.png') # save a screenshot to disk
sbtn = driver.find_element_by_css_selector('button.gbqfba')
sbtn.click()
When I try to run it I get the following error:
WebDriverException - "Unable to start phantomjs with ghostdriver."
Apparently, this error can be solved by replacing the 3rd line with:
driver = webdriver.PhantomJS(executable_path='/usr/local/lib/node_modules/phantomjs/lib/phantom/bin/phantomjs')
I'm using Windows7, and the path for me appears to be: "C:\Users\myname\AppData\Roaming\npm\node_modules\phantomjs\bin\phantomjs". I have tried using this and variations of it as the executable_path, but I still get the same error. I have also tried adding the folder location to the path. Nothing has worked. I suspect that I am missing something pretty obvious.
Aha!
It was a slightly different location. The line I was looking for was:
driver = webdriver.PhantomJS(executable_path=r'C:\Users\myname\AppData\Roaming\npm\node_modules\phantomjs\lib\phantom\phantomjs')

Resources