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!
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 am trying to autoamte the eBay mobile native app using Selenium Appium.I am able to retrieve the page elements of all the pages however for the Sign In page I am not. I am getting error message in both UIAutomator and Appium Inspector 1.6.5 keeps searching with no response. I would like to know if the issue is with the eBay page or is there any other alternative ways to find the locators.
Steps to reproduce:
1. Search any object in ebay -> go to details page -> Click on watch
CaptureImage Issue
This issue occur if your appium server is on OR APP in mobile or emulator, now again open the app and navigate to screen you wanted. try this time
OR
stop your server and close this uiautomatorviwer and again open uiautomatorviwer. Your will not get the error this time.
another way to locate element is:-
Use below code :-
System.out.println("source : "+ driver.getPageSource());
driver.getPageSource() will return you the XML of screen.
Now you can construct an xpath on your element.
Use below link to beautify your xml
http://xmlbeautifier.com/
Use below code to validate your xpath
https://www.freeformatter.com/xpath-tester.html
Hope it will help you :)
I have login form on website,
i want to make automatic testcase for this scenario:
i give phone number but no password:
How do I test selenium to give me expected red error message popup?
What function is in selenium api to check for it? I did not find it!
EDIT: or maybe my expected thing to happen should be "stay on same page"?
There is no specific function like that. Find out what is the xpath for that red colored text. Then you can create a web element using that xpath and check whether it is visible and what is the text value of that element, and assert on that.
As an example:
You first define the error message WebElement as messageElement
You may locate the element like this:
driver.findElement(By.id("error-message"))
Then you may get the error message text using this:
messageElement.getText());
Once you get the text you can then validate it with the expected text.
Assert.assertEquals(actualMessage, expectedMessage);
PS:
From snap, it doesn't seem to be another pop-up so no need to use switch to alert etc.
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
In IE and FF, i can attach an event handler to onBeforeUnload, and by passing a string to a property of the event, the user will see a dialog asking him whether he wants to continue with the "unloading" (either closing the window or navigating away).
Safari and Chrome don't support onBeforeUnload, and onUnload seems to be too late.
Is there some way to replicate the same functionality in Safari/Chrome?
NOTE: I'm not trying to keep the user hostage. I know this is nagging and un-cool. In fact, my site goes to great lengths to let the user go freely, and have everything in its place when they come back.
However, I am hosting other sites inside IFrames, and sometimes these decide to get rid of me and take over the browser, which is what I'm trying to avoid.
Thanks!
This works perfectly for me in both Chrome and Safari:
<html><body><p>Test</p>
<script>window.onbeforeunload = function() { return "Sure?"; }</script>
</body></html>
When I try to close the window, I get the prompt.
StackOverflow itself uses onbeforeunload, and it works fine for me in Safari:
function setConfirmUnload(a){window.onbeforeunload=a?function(){return a}:null}
I checked it in chrome and it seems to be working fine using this:
<body onunload="alert('x');" onbeforeunload="test1();">
This question is covered in slightly more detail in another newer StackOverFlow question:
Setting onbeforeunload on body element in Chrome and IE using jQuery