In this question an answer is given on how to handle authentication popup with Selenium WebDriver using Java. Now, can this be used also for python? It looks like the python driver has no class UserAndPassword like the Java pendant has.
Here is what I have tried:
wait = WebDriverWait(driver, 10)
alert = wait.until(ExpectedConditions.alertIsPresent())
alert.authenticateUsing(UserAndPassword("user","passwd"))
Indeed there is no such class in python selenium library, but you can easly navigate to given alert and input user and password using other means.
wait = WebDriverWait(driver, 10)
alert = wait.until(ExpectedConditions.alert_is_present())
alert = driver.switch_to_alert()
alert.send_keys('username')
alert.send_keys(Keys.TAB)
alert.send_keys('password')
alert.accept()
This will work on standard authentication, if it is custom made one you will probably have tinker with it abit.
Related
I want to allow the Pop-ups and redirect setting of chrome using selenium java. Is there any way?
In pop-ups logic we have to mention below logic,
WebDriver driver = new ChromeDriver();
String url = " https://www.google.com";
driver.get(url);
For more clarification please gothrough the link1 first example
I try to load webpage and extract some docs, but after typing in code and pressing "search" button, nothing shows up. When i do it on my regular website, it works fine. Should I somehow set my WebDriver differently?
I tried with simple firefox driver but it also failed.
WebDriver driver = new InternetExplorerDriver();
driver.get("https://ekrs.ms.gov.pl/rdf/pd/");
WebElement krsinput = driver.findElement(By.name("unloggedForm:krs2"));
krsinput.sendKeys(String.valueOf(myNumber);
WebElement szukajbutton = driver.findElement(By.name("unloggedForm:submit"));
szukajbutton.click();
I typed in "331515" in the inputbox (there's only one) and after pressing "szukaj", there should be table showing below button.
First, there is a tip on input field: Pole KRS jest dziesięcioznakowe.
So, your code should look like
String strMyNumber = "0000331515";
WebDriver driver = new InternetExplorerDriver();
driver.get("https://ekrs.ms.gov.pl/rdf/pd/");
WebElement krsinput = driver.findElement(By.name("unloggedForm:krs2"));
krsinput.sendKeys(strMyNumber);
WebElement szukajbutton = driver.findElement(By.name("unloggedForm:submit"));
szukajbutton.click();
And your code is fully workable.
By my opinion, it's a website's issue. I have tried few correct format case numbers that I've found on some Polish websites, all of them gave no result to me.
I would like to save some resources on my low-spec Windows boxes by running the browser in a headless mode. As far as I am aware, PhantomJS + GhostDriver is the standard choice for such task to be used with Selenium Webdriver. However after trying it and immediately running into issues with alerts handling which doesn't seem to be supported by PhantomJS. Specifically, the following exception is returned:
[ERROR - 2016-08-01T04:24:24.894Z] RouterReqHand - _handle.error - {"name":"Invalid Command Method"," . . . "}
as a result of not supporting getAlertText WebDriver Command when performing:
Alert alert = driver.switchTo().alert();
and specifically this method implemented in EventFiringWebDriver:
public Alert alert() {
return targetLocator.alert();
}
I am looking for an alternative approach or a feasible workaround. Anyone?
I have been able to work around that by executing the alert handling using JavaScript directly like this:
JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
jsExecutor.executeScript("window.alert = function(){}");
jsExecutor.executeScript("window.confirm = function(){return true;}");
At the moment, there seem to be no way to perform that operation directly via WebDriver interface for PhantomJS.
I used the Actions to mouse hover in FF and chrome , it is working fine. But the same code is not working in safari. I am using mac OS and selenium webdriver and java.
I tried below code.
new Actions(driver).moveToElement(element).build().perform();
JS:
String mouseOverScript = "if(document.createEvent){var evObj = document.createEvent('MouseEvents');evObj.initEvent('mouseover', true, false); arguments[0].dispatchEvent(evObj);} else if(document.createEventObject) { arguments[0].fireEvent('onmouseover');}";
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript(mouseOverScript, element);
It is a show stopper issue. any help is appreciated.
Performing mouse hovers requires using WebDriver's Advanced User Interactions API. In the Java language bindings, this is accomplished by the Actions class. Unfortunately, at present, the SafariDriver does not implement the Advanced User Interactions API, so you cannot accomplish this directly. Until it is implemented, you could probably simulate it using JavaScript to fire the events fired my a mouse hover.
This question is about the Java API of Selenium 2 RC2, used with Firefox 4.
Let's say i have a WebDriver instance open and made some interactions in that browser window, like opening a URL, clicking on a link and filling out a form.
Is it possible to create a new WebDriver instance which uses the already open window? Something like this (pseudo code):
WebDriver webDriver1 = new FireFoxWebDriver();
webDriver.doSomeStuff();
String webDriverInstanceId = webDriver.getId();
WebDriver webDriver2 = new FireFoxWebDriver(webDriverInstanceId);
webDriver.continueDoingMoreStuffInSameWindow();
There is no "attach to an existing instance of a browser" functionality in the Selenium WebDriver API yet. This is true regardless of whether WebDriver or a different process started the instance of the browser you want to attach to. There is an open feature request for it.