How can I store a dynamic text value in selenium ide and use it later in different window - selenium

I am new in selenium and trying to learning. I am creating a script and I got stuck here, I want to store a dynamic value from text message on web page ex. " Event Name:Test" this Event Name is dynamic and I want to store this and want to get in other window. In 2nd window i want to use this value(Test) to verify in the page
I tried storeValue, StoreText and storeAttribute command and getting error message for xpath or "element not found".
Please help me and advice me , what should I do?
Can You please suggest me the Xpath for storing and retrieving the event name. Please help me...
Thanks in advance,
Niru

If you are using the same test-case to navigate from page 1 to page 2 you can use the storeText function in the IDE to store the value of your event name. And then you can use the same variable in the page 2 for verification.
For example, in page 1 to store the value of event you use:
storeText(locator1, temp)
And then on page 2 you use assert:
assertText(locator2, ${temp})

Related

RSelenium: Entering search term - trouble with css selector

I am trying to trigger a search on this site. First, I want to enter a search term, then click the search button. I am able to to do the second step, however I am unfortunately unable to access the search field. Below my attempt.
Start RSelenium
link_to_page<-"https://www.cec.ro/sucursale"
library(RSelenium)
rD <- rsDriver(browser = "firefox", port = 483L, verbose = F)
remDr <- rD[["client"]]
# Navigate to site, and wait
remDr$navigate(link_to_page)
Sys.sleep(5)
#Search for element by its id
remDr$findElement(using="css", "#edit-localitate--_jjPr3WukFY")
Error: Summary: NoSuchElement
Detail: An element could not be located on the page using the given search parameters.
class: org.openqa.selenium.NoSuchElementException
Further Details: run errorDetails method
There is apparently something wrong with the css selector. I checked, it's not nested in an iframe or so, but mabe it's related to the 'form' element it is nested in? Grateful for any hint. Many thanks.
The error is NoSuchElement which indicates an element could not be located on the page using the given search parameter
The second part of the classname i.e. _jjPr3WukFY is dynamically generated and is bound to change sooner/later. They may change next time you access the application afresh or even while next application startup. So can't be used in locators.
Solution
You need to consider any of the other attributes which is static in nature. Example:
remDr$findElement(using="css", "button[id^edit-localitate]")
or
remDr$findElement(using="xpath", "//button[starts-with(#id, 'edit-localitate')]")

Unable to access the element in the frame

I am still dipping my toes in selenium , I am SAP guy working on Selenium automation POC. my requirement is to click on the drop down and select a value from the droplist.
I have extensively looked at the previous posts but could not find any answers. I have tried all the suggestions from the post but nothing seems to be working for me.
Please can you help me how to access this drop down value.
HTML code is attached in the pic along with the element that I am trying to access
My selenium code :
driver.switchTo().frame(driver.findElement(By.name("SMFrame")));
System.out.println("TExt" + driver.findElement(By.xpath("//div[#class='file-type']")).getText());
Error:
error -- > no such element: Unable to locate element: {"method":"xpath","selector":"//div[#class='file-type']"}
Image
Assuming you are correctly getting into the iframe
Right now you are selecting a div above the actual dropdown element (the select-dropdown tag). You may want to try changing your xpath to search for the tag like so:
//div[#class='file-dropdown']/select-dropdown
Also you should be creating a dropdown object like this. Then calling a method on it to select the dropdown option you are looking for:
Select dropdown = new Select(driver.findElement(By.xpath("//div[#class='file-dropdown']/select-dropdown");
System.out.println(dropdown.selectByVisibleText("text that you are looking for in the options"));
This is a good explanation of how to do it: https://www.javatpoint.com/selenium-webdriver-handling-drop-downs

How to locate random id generated by a modal?

I was testing my website using RF. The problem is, every time the modal is opened, a different id(locator) will be set on the textbox that I want to input my text. How do you get value of this locator?
I was supposed to try Get Element Attribute but then it cannot support my problem since it still requires a specific locator.
In ROBOT Framework (RF), the locator can be accessed by several ways. Please refer and read this link: http://robotframework.org/Selenium2Library/Selenium2Library.html
The most common way to access the locator is by id such as :
Input Text id:username # Element with id 'username'.
Input Text id:password # Element with id 'password'. you can also use 'Input Password' keyword.
However, if the 'id' element is so dynamic which it keep changing, then the best alternative is to use either ABSOLUTE XPATH expression or CSS selectors. Install the XPATH add-on in your web browser. For firefox, just install ChroPath.
Then, get the ABSOLUTE Xpath element of that username & password text box. Let's assume we know the absolute xpath expression already, so in ROBOT, you can write like below.
${login_absolute_xpath}= Set Variable xpath=/html[1]//div[7]/form[1]/div[1]/input[1]
${password_absolute_xpath}= Set Variable xpath=/html[1]//div[7]/form[1]/div[2]/input[1]
Wait Until Page Contains Element xpath=${login_absolute_xpath}
Input Text xpath=${login_absolute_xpath}
Input Text xpath=${password_absolute_xpath}
...
This should works. Please let me know if this helps.

Selenium Command

When we use selenium command at that time command not find and attribute not get? See below command.
<table>
<tr><td>open</td><td>http://www.wikipedia.org/</td><td></td></tr>
<tr><td>verifyAttribute</td><td>css=input#searchInput</td><td>(Search Input)</td></tr>
<tr><td>assertAttribute</td><td>css=input#searchInput</td><td>(Search Input)</td></tr>
<tr><td>verifyAttribute</td><td>css=input#searchInput</td><td>language</td></tr>
<tr><td>verifyAttribute</td><td>xpath=//div[2]#class central-featured</td><td>central-featured</td></tr>
<tr><td>verifyAttribute</td><td>xpath=//div[2]#class central-featured</td><td>search1</td></tr>
<tr><td>assertAttribute</td><td>xpath=//div[2]#class central-featured</td><td>central-featured</td></tr>
</table>
I am using Selenium IDE 2.5.0 in Mozilla Firefox and Ubuntu.
Xpath //div[2]#class central-featured is invalid. Try changing it to //div[#class='central-featured']/#class if you mean to select a class.
You could also use assertElementPresent function instead of selecting attribute, if the whole point is to check that element exists, i.e.:
<tr><td>assertElementPresent</td><td>xpath=//div[#class='central-featured']</td><td></td></tr>
Much simpler that way.
Use xPaths in this case.
Use google chrome's built in developer tool for this
Place your cursor on the element
Press Ctrl+Shift+C
Click the Element
That clicked Element's code is highlighted in the short window on the bottom
Right-Click on highlighted code
Select Copy > Copy XPath
Here it is you have copied the xPath for that specific element. This is shown in the image:
Click to see how to copy xPath
The Xpath you have used in Invalid.
You can use xpath as follows and through this you can fins xpath of any object - just need to study the concept:
Here as we can see we want to search Google Search just by writing its xpath in console
So to find the Google Search button we have to write xpath like this
//span[#id='gbqfsa']
Once we hit enter it would bring
[ gbqfsa">​Google Search​​ ],
It shows that xpath for Google Search Button is correctly written
Now suppose we want to search Google Search button if we are just familiar that id attributes start with gbqfs
then we have to use function starts-with like this
//span[starts-with(#id,'gbqfs')]
and once when we hit enter on console it would reflect two button one is Google Searchand Second one is I’m Feeling Lucky
[
gbqfsa">​Google Search​​
,
​I'm Feeling Lucky​​
]
So to find out the Google Search uniquely we need to complete id attribute to gbqfsa
“//span[starts-with(#id,'gbqfsa')]
and hit to enter and now it would reflect only
[
​Google Search​​
],
It proves that we have written right xpath for Google Search
In the same fashion we can use Contains function to find the Google Search button like this
here I have taken fsa from gbqfsa
//span[contains(#id,'fsa')]
hit enter and hopefully it will return
[
​Google Search​​
],
if there are multiple attributes then we can use:
//span[contains(#id,'fsa') and contains(#class, 'xyz')] hit enter and hopefully it will return
Information Source: Sumit Mittal Blog
You can use CssSelector as below
webDriver.findElements(By.cssSelector("div.central-featured")) // for more than 1 elements with same class
webDriver.findElement(By.cssSelector("div.central-featured")) // for 1 element

Not able to get tooltip text using Selenium WebDriver

I have 5 tooltips in page. Using WebDriver, I am trying to verify these tooltip text.
I am using following code sequentially to get the tooltip text of all 5 elements:
Actions builder = new Actions(WebDriver);
builder.ClickAndHold(Element1).Perform();
Console.WriteLine(Element1ToolTip.text);
builder.ClickAndHold(Element2).Perform();
Console.WriteLine(Element2ToolTip.text);
builder.ClickAndHold(Element3).Perform();
Console.WriteLine(Element3ToolTip.text);
The issue is I get only the tooltip text of first element printed in console.
Is it because I need to refresh or reset the builder?
It's really weird when I delete the code for 1st element , then I can get tooltip text of 2nd element. So, basically it is getting tooltip text only once in single execution.
Verify tool tip by comparing "title" attribute of the web element and your expected tool tip text.
Console.WriteLine(Element1.GetAttribute("title"));
Console.WriteLine(Element2.GetAttribute("title"));
Tool tip text for input elements would be the title attributes and for images, alt attribute would be the tool tip.This is the standard for HTML 4, so I am not sure if you need to do hover and all.
Console.WriteLine(InputElement1.GetAttribute("title"));
Console.WriteLine(ImageElement1.GetAttribute("alt"));
http://www.javascriptkit.com/howto/toolmsg.shtml
I think, it needs to release from element as:
builder.release(Element1).perform();
So, your code could be as below:
Actions builder = new Actions(WebDriver);
builder.ClickAndHold(Element1).Perform();
Console.WriteLine(Element1ToolTip.text);
builder.release(Element1).perform();
builder.ClickAndHold(Element2).Perform();
Console.WriteLine(Element2ToolTip.text);
builder.release(Element2).perform();
builder.ClickAndHold(Element3).Perform();
Console.WriteLine(Element3ToolTip.text);
builder.release(Element3).perform();
I am facing the same issue , i checked the view source page on running the test and it appears that the title attribute is displayed as data-original-title.Due to which it is unable to display the text.On replacing the title with data-original-title . I am able to obtain text.