Not able to verify text after login with selenium Webdriver script - selenium

I am trying to automate login functionality with selenium webdriver using TestNG framework. I want to verify the text after login like Hi [username#gmail.com].
This is the order in which links are present on page :
TrackOrder | Notification | Singnup | Login
My method of doing:
I clicked on Login (login window appears) and I sign in. After login
the order in which links are present on page are :
TrackOrder | Notification | Hi[username#gmail.com]
For verifying text after login :
I am extracting the xPath of web element Hi[username#gmail.com] and using getText() method to verify actual and expected value.
Actual problem:
As soon as I run script , it logs in successfully but when I extract the text of web element it is printing signup. Though login is done successfully why is it showing up singup?

The reason for printing signup maybe that either the XPath you gave, is not explicitly identifying the username element and just give the element next to Notification element, or the signup element text is changing to username text after login.
So, better to create unique XPath for your element and wait for some time before using getText() method.
Thread.sleep() can be used if the text of the element is changing on login as selenium will execute the method before the change in text value.

Try to use Absolute Xpath of the Web Element.

Related

Javascript Login Popup

Can you please suggest how to handle login popup on Chrome using Selenium :
Since org.openqa.selenium.security.UserAndPassword removed from Selenium 3.0 and above, how to progress with the login ?
Check these out 1 and 2.
The second video though used with Firefox explains that to pass a username and password through the url itself. For example when calling the driver.get() function you can pass the username in password of the page by the following.
driver.get("https://username:password#domain.com")
Website 1 however does it by passing it through Selenium's server and lists various other methods with out using the url.
Refer to link 1's methods 2 and 3 for use without using the url method.

How to check xpath element exist in webpage using workfusion studio?

Check xpath element exist in opened webpage using workfusion studio conditional action.
Currently i'm using webelement Actions Library to login on specific website. its working fine.
But when i already logined then its give me an error on login steps because its redirected on home page directly.
So, I want to check if Xpath element is exist on my webpage or not.
To accomplish a check, you can create an Exception Handling block, and put a Mouse Click by this XPath inside the "Try to completeā€ block.
Alternatively, you can use the Retry block or add more Wait time

How to identify Facebook timeline element to post something with Robot Framework?

Can you help me to identify element ID or any other locator of timeline composer in Facebook profile ?
I need this to use in Robot framework with selenium2library to post something on my wall.
I can log in to Facebook, navigate to profile, but I cant input text into timeline composer. I tried to use Click element before inserting text, but no success.
I am using "inspect element" in browsers/firebug add-on to identify elements.
In this case, unfortunately all locators I have tried giving errors like:
Element does not appear in 5 seconds
or
Element must be user editable in order to clear it
Non dynamic locator for FB timeline-composer has name "xhpc_message_text" (18.10.2016)
Input text name=xhpc_message_text test

How to map xpath of web element in its actual class?

I am creating a framework in selenium from scratch where i am scripting below scenarios:
1.Login in to https://www.yahoomail.com
2.entering username
3.entering password
4.click on Sign-In
5.click on Compose button
6.Enter Email ID, Subject and Message body.
Below is the code script i have written for above scenario:
WebDriver oYahoo = new FirefoxDriver();
oYahoo.get("http://www.yahoomail.com/");
oYahoo.manage().window().maximize();
oYahoo.findElement(By.xpath(".//*[#id='login-username']")).sendKeys("abcdefasdf#yahoo.com");
oYahoo.findElement(By.xpath(".//*[#id='login-passwd']")).sendKeys("sfgas234#123");
oYahoo.findElement(By.xpath(".//*[#id='login-signin']")).click();
oYahoo.findElement(By.xpath(".//*[#id='Compose']/button")).click();
oYahoo.findElement(By.xpath(".//*[#id='yui_3_16_0_1_1448364357109_2222']")).sendKeys("abcdefgh#gmail.com");
oYahoo.findElement(By.xpath(".//*[#id='subject-field']")).sendKeys("Hi This is my first automated mail");
oYahoo.findElement(By.xpath(".//*[#id='yui_3_16_0_1_1448364357109_1966']")).sendKeys("Hi This is my first automated mail");
oYahoo.findElement(By.xpath(".//*[#id='yui_3_16_0_1_1448364357109_2465']")).click();
oYahoo.quit();
Scripts fine till it clicks on "Compose" button, Once i get Mail editor, Script does not enters email-ID,Subject, and Message body.
What other action i should perform to achieve the same so that script will enter these parameters and can send a mail to particular user.
Do we need to create some class which will maps the locators to "compose-Email" screen?
If yes, how we can map/assign x-path to particular web element of Compose-Email page.
Thanks in Advance.
Well you should try by using the xpath and enter the required text. Something like this (it works for me)-
oYahoo.findElement(By.xpath(".//*[#id='to-field']")).sendKeys("xxxx#xxx.com");
oYahoo.findElement(By.xpath(".//*[#id='subject-field']")).sendKeys("My first automated email");
oYahoo.findElement(By.id("rtetext")).sendKeys("Hello....Hi....This is my first automated email");

How do I check for error message popup in browser using webdriver?

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.