I am using Selenium Chrome Driver to test my application.
There is one page in the Browser where on Load an Alert message appears and I have to Click OK.
The problem is when I try to use driver.SwitchTo().Alert in my code. The Alert appears on the foreground page while the page is still loading. When I continue to debug at this point, my driver waits for an infinite time, and when I click manually on OK button, then it tries to switchto().alert, but since there is no Alert, it fails.
I would appreciate any help on this.
Note: The Page is in Loading Form till I click on Ok button on Alert , I wonder if it is alert
I also followed the below solution , but it does not work for me
https://groups.google.com/forum/#!topic/selenium-users/CixorzKZE4E
I get the following exception ,
he HTTP request to the remote WebDriver server for URL localhost:3200/session/0285afd8049f70878988405463448d24/… timed out after 60 seconds.
I can still see alert on my child window .
you could use explicit wait for the loading part.ie if webdriver instance is driver
WebDriverWait wait=new WebDriverWait(driver, //mention the time as per need here ie 20);
wait.until(ExpectedConditions.urlToBe("mention the url"));
before the alert handling code.
you need to accept or dismiss the alert, code you can try :
driver.switchTo().alert().accept();
I find out that the alert was a Javascript alert and how to handle javascript alerts is mentioned in Selenium Documentation.
Related
I'm writing a code using Selenium and Chromedriver to remotely control my instagram.
I've managed to login to the platform however as soon as I do a pop up asking about activating notifications appears and my codeflow breaks because it can no longer click the elements of the instagram page.
this is the code I tried using (which works during login to click the "send" button
notifBtn= self.browser.find_element_by_css_selector('button')
notifBtn.click()
(since it's the first instance of button on the web code it should automatically select that one)
however this time the browser is stuck and doesn't do anything.
during the login I had a problem where it wouldn't click either and found that it was because there was a lag between the request to go to the instagram login page and loading the page so it could find the CSS elements. I fixed it by adding
time.sleep(2)
before inputting the data and it fixed. I thought something similar would work here as it doesn't load instantly but it made no difference.
Is this an issue with the selector, as in could I use xpath to get around it? anyways sorry if it's a bit vague and feel free to ask me about my code or whatever.
notifBtn= self.browser.find_element_by_css_selector('button')
notifBtn.click()
I expect Chromedriver to click don't activate in the pop up so the code can continue instead I get stuck on that screen
Your find_element_by_css_selector call is probably locating multiple elements, and doesn't know which one to click. I would use an XPath here, to be more explicit about which button you are trying to click:
from selenium.webdriver.support import expected_conditions as EC
# Wait for button to exist
not_now_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//button[text()='Not Now']")))
# Click the button
not_now_button.click()
I was trying to capture or (find the css/xpath) the inline warning message that disappears after few seconds (BTW, I am using Selenium WebDriver / Java for my automation).
eg: In the below public link, I try to click Reset Button without entering any email. The text box briefly shows 'Please fill out this field." I want to automate if it is showing this message as expected.
https://app.shipt.com/password_resets/new
Please help.
PS: I tried to search this website and google but could not find any useful information.
For actions that appear or disappear after certain time you should use Expected Conditions:
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));
And then you can click on element as usual.
However in case of the shipit page you are trying to automate the popup is a native HTML5 popup, so you cannot use Selenium directly to get the message, and you have to use this workaround:
Stackoverflow - how to get HTML5 error message in Selenium
I want to automate "amazon-add-to-cart" procedure.
the flow is to send http get method of the requested items, and then
submitting a button of the returning html.
the 1st url for example is:
https://www.amazon.com/gp/aws/cart/add.html?AssociateTag=your-tag&ASIN.1=B003IXYJYO&Quantity.1=2&ASIN.2=B0002KR8J4&Quantity.2=1&ASIN.3=B0002ZP18E&Quantity.3=1&ASIN.4=B0002ZP3ZA&Quantity.4=2&ASIN.5=B004J2JG6O&Quantity.5=1%22
after that the user should click the continue button in order to indeed adding the items to the cart.
can you provide an example of how to code this flow with the button click using java selenium - without openning the browser?
thanks.
use the "HTMLUnitDriver" Webdriver
WebDriver driver = new HtmlUnitDriver();
driver.get("Enter the URL");
I just started using Selenium Web Driver to test an online banking transaction application.
I love it, but there is something that annoy me. Let say i access the login screen with this code:
driver.get("https://webdev.myurl:18113/");
WebElement element = driver.findElement(By.name("username"));
element.sendKeys("xxxx");
element.submit();
the browser start and the page load and display. But it look like the page try loading element from an external site and the findElement (2nd line) wait for these request to complete!
Is there a way to bypass this beahvior?
I tried this too :
WebElement element = (new WebDriverWait(driver, 10)).until(new ExpectedCondition<WebElement>() {
#Override
public WebElement apply(WebDriver d) {
return d.findElement(By.name("username"));
}
});
But it does not help since this line seems to execute only when the page is totally loaded.
EDIT: I spoke with one of the guy here.. and he told me ipinvite.iperceptions.com is not called by our app.!!! and in fact when i load the site in FF, i don't see this call?!
Does Selenium web driver call this site : ipinvite.iperceptions.com?
Anyone have the same issue?
You can try setting implicitly wait time and page load time to 0. Google "selenium implicitly wait time" and "selenium page load time."
Time outs on get function have not been implemented yet.
When creating a new FirefoxDriver, there are overloads in the constructor that allow you to specify a command timeout which is the maximum time to wait for each command.
You could refer to the answer on this post
ok, i found the problem. I commented out the setPreference to my FirefoxProfile that was setting the proxy parameters. I noticed i did not need them anyway. And now there is no more call to this wierd ipinvite.iperception.com!
Thanks for the time you took to reply
Regards
In my application I have alert on pageload.
The alert comes when i visited a specific page of my application and it is on page load.
I tried by:
selenium.click("click on the button, which takes me to a new page");
if(selenium.isAlertPresent())
selenium.getAlert();
selenium.waitForPageToLoad("30000");
But no luck. Can any one please help me how to handle alert in selenium RC on page load?
Screenshot:
screenshot http://content.screencast.com/users/mahadi_OP/folders/Jing/media/77e6c00e-e146-455c-861a-03d3cab9027d/2012-01-08_1703.png
As far as i know Selenium does NOT support javascript alerts that are generated in a page's onload() event handler. I had the same problem, and the only workaround for me was not to depend on alert in my tests. But maybe these articles will be any use for you:
Link 1
Link 2