So I'm using Selenium for java and am trying to grab some text from a website after connecting to it. I know selenium has
driver.getPageSource();
But if there are variables it will return the variables and not the actual data, for example if the actual text I want is
13-11-28
What it actually is in the source is
/month
or something like that. How can I get the actual text using selenium or another library.
You could find the element and the perform 'getText' on it.
Example
driver.findElement(By.cssSelector(".month").getText())
Related
I need to verify that a specific string of text is present on webpage and check the number of occurences in LeanFT. I have tried code below to verify if text is present:
browser = BrowserFactory.launch(BrowserType.CHROME);
browser.getVisibleText().contains("Success");
I don't think getVisibleText on Browser is the best fit for the problem you're facing. AFAIK getVisibleText uses OCR and not the application's underlying technology.
A better way, I think, would be to identify the Web.Element that contains "Success". If you don't want to bother getting the specific element you can use the Page's text property.
I'm not familiar with LeanFT's Java SDK but in JavaScript it would be written like this:
expect(browser.$(Web.Page({})).text()).toContain("Success");
Edit: according to comments (thanks #Adelin), the Java equivalent is:
browser.getPage().getText().contains("Success");
I want to select and click on the object present inside inner html (shown in the image). But the object is not getting identified. I am using Java.
Note --> my application not opening with any browser except Internet Explorer and I can't verify xpath from console/debugger so I have to verify it through code only.
Code I have tried so far but not working for me-->
option 1 -->
driver.switchTo().frame("nav");
driver.findElement(By.xpath("//a href[#text='Administrate']")).click();
option 2 -->
driver.switchTo().frame("nav");
driver.findElement(By.xpath("//a[#text='Administrate']")).click();
option 3 -->
driver.findElement(By.xpath("/html/frameset/frame[1]/html/body/ul/li/ul/li[1]")).click();
You are checking for exact text match, use contains instead
driver.findElement(By.xpath("//a[contains(text(), 'Administrate')]")).click();
Or
driver.findElement(By.xpath("//a[contains(., 'Administrate')]")).click();
Please note the difference between text() and #text
You need to change your XPath like
driver.switchTo().frame("nav");
driver.findElement(By.xpath("//a[text()='Administrate system']")).click();
Note:- Here you need to pass complete string for better learning please refer Firepath to create and evaluate your xpath
Also can use contains method to find an element on partial text basis
I have a form. I automated the task of filling up the form and clicking the submit button using Selenium WebDriver.
Now in the next page where the URL has changed, there is a confirmation message "Form Submitted Successfully". How do I verify this element in the new URL?
Thanks in advance!
Try to use JUnit assertion to compare expected string with actual the one you getting on the page, this should work :
String actual = driver.findElement(By.xpath("your_locator").getText();
Assert.assertEquals(actual, expected);
As per my knowledge, even if the objects you are working on are on different page(url) it does not matter, you just need to have your locator correctly written.
Using getText() method you could get text on the page. Verify whether your locator is pointing to correct text using xpath validaters or other means.
Once you have your locator handy apply getText() method on it and get the text.
Once you have text, just verify it or print it to see if it is the same.
I have a fairly simple question, but I'm unable to find a working answer.
I'm using javascript in my HTML file for a page that is taking input from the page and giving me back a string of a jSON object. All that I want to do is take this string and put it in a Java string.
I can do things like
target.appendJavaScript("s=getString();");
target.appendJavaScript("alert(s);")
which give me the desired information in the alert. But how do I get s into a Java string?
I have tried the following
StringValue temp = RequestCycle.get().getRequest().getQueryParameters().getParameterValue("s");
info(temp.toString());
And other variations like getRequestParameters(), but I get nulls on temp.
These actions are inside an AjaxFallbackButton's onSubmit.
Any advice on how to get a javascript var in Java?
Although I would still like to know more about sharing variables between Java and Javascript in HTML, my case was solved thanks to Wicket.
The value that I was retrieving with s=getString() was already accessible in a HiddenField, and so I simply needed to get it a wicket:id in the HTML and add it with a property model in the Java. Hopefully this might help someone else in the future.
Is it possible to edit browser's text field using java? Currently I'm using Jsoup to gather some information about websites so I'm looking for some more options.Could JSoup to this? Thank you!
I don't see how JSoup would help here. JSoup is just a way to parse html. You could use it to write out some html that has a text field in it with an input tag that has a value attribute on it. Then when you render the file in a browser, the page would have that value. But since you haven't given us very much information, I'm not sure if this is exactly what you want to do or completely different from what you want to do.
This is probably the last thing you'd want to do (not the first), but you could set the values of a text field using Java's Robot class.