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
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()
While I am trying to automate the makemytrip website it shows some notification message from google. I don't know how to handle that notification. It shows NosuchElementException while using the web element id from html source code.
It is an iFrame hence the NosuchElement exception.
You need to switchTo().frame in your case it should look like this:
driver.switchTo().frame("notification-frame-~5586290a");
After switching into the iframe you can click the buttons there...
In your case, if you want to close it do something like:
driver.FindElementsByXPath('//*[#class="wewidgeticon we_close icon-large"]').click()
If you do not close it but want to go back to the default frame just use:
driver.switchTo().defaultContent();
Hope this helps you!
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 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.
I am trying to click the main menu items in seleniumhq.org but after clicking on the first link i am getting a StaleElementReferenceException:Element not found in the cache=perhaps the page was changed since it was looked up
Please provide solution to solve the above problem
Below was my code
WebDriver d=new FirefoxDriver();
d.get("http://docs.seleniumhq.org/");
d.manage().timeouts().implicitlyWait(100,TimeUnit.SECONDS);
List<WebElement> l=d.findElements(By.cssSelector("ul>li"));
for(WebElement e:l) {
e.click();
}
Thanks in advance
If you click on a link and you are taken to the different page or even if you stay in same page the DOM is refreshed. Those elements are not attached to DOM anymore. You need to write some code to come back to previous page if your click takes you to a different page or even if you stays in same page you have find the link on the fly to click instead of "e.click()"