I dont understand this output produced by selenium webdriver java - java

I'm trying to write an application for the game Path of Exile, that lists the items in my stash on trading websites automatically.
For this I have to retrieve the items in my stash from their website. For some reason the ".getText()" functions is behaving very weird on the website. I really can't see any mistakes I did with the x-path Expressions.
Example:
Here you can see a snippet from the HTML file I am working on
screenshot of browser debugg tool
In the screenshot you can see that the x-Path I am using is selecting a element with a text element, however when I iterate over the elements and get the text with the getText() function, it returns a empty String... I really have no clue what I am doing wrong, is it the website, that is denying me to access the field?
In case it helps I add here a screenshot of the source code for outputting the text fields
printing the text of the elements(SourceCode)
5 empty Strings as output

On your place I would try to get value instead of text.
try to replace
e.getText()
with
e.getAttribute("value")
or you can also try to play with .getCssValue()

Related

Filling out a web form automatically with a text file

I request a web page in the browser and I should fill out the text boxes it has. They are too many text boxes and it takes too mush time too fill them and the result of this latency is an expired page. I have written those inputs in a text file (each line for each text box). I want to write a program that when it is running, it fills out the form and I just click the submit button of the website.
The form is something like the following image:
I have a form which somehow looks like the following image:
I searched a lot to find a way to fill out the text boxes automatically in C# but did not find anything. My question is that is there anyway to set the values of these text boxes in C# and send them back to server?
You can write a json object, then a javascript function that iterate that json and figure out by each value the selector of the correct input to use and set the correct value.
Then when the page open, use the dev console.
paste the json object, paste the function.
Run the function and the form should get fill out.
=)

getting the text from an WebElement

Say I have an element (doesn't really matter what. Let's say "//div[#id='tony']/div/span" but any xpath would be OK.
To get the text on a page from this you could do something like
WebElement ele = driver.findElement(By.xpath("//div[#id='tony']/div/span"));
System.out.println(ele.getText());
// Or an our system someone wrote a method so we can get all text in that
// element and everything underneath (part of that element)
System.out.println(getText(ele));
This is fine when you are running the program. But originally when you are writing and debugging with Chrome before you actually write the program. In Chrome you can do right click -> inspect and then in the bottom do a ctrl-f which opens a search box and you can type an xpath and it will highlight it (them) on the page.
Now I swear several months ago when I was debugging I could also have it display the text in that element but I don't remember how? You type something into the search box like get-text(//div[#id='tony']/div/span) but I can't remember or figure it out. Perhaps at the time I was using Firebug and not Chrome?
Does anyone know a way to have it print the text of the element? I know you can eyeball it in the HTML code but what you think is the text and what it actually is is not always the same

Unable to retrieve Textbox Value In Selenium Testing

I am new to Selenium testing, I am trying to put the value into the textbox with the help of xpath, name & id. (java using eclipse IDE):
driver.findElement(By.xpath(".//* [#id='txtEmpDepAddressLine1']")).sendKeys("2nd Main")
driver.findElement(By.xpath(".//*[#id='txtEmpDepAddressLine2']")).sendKeys("Bangalore");
While running, textbox is not retrieve the from the above code. Can anyone help me out to solve this problem?
Use By.id instead By.xpath
If you insist xpath then:
Start with: // instead: .//
Make sure the id value is unique on page.
if using xpath in some browsers id or ID makes differnce.
It is difficult to say without the HTML, but I'd suggest a few things:
Open your page, go to the Google Chrome DevTools console, and verify you can locate the element using your xpath. So you'd type:
$x("//* [#id='txtEmpDepAddressLine1']")
and verify the text box is located.
If the sendKeys isn't working on the element at that id, I'd wonder if it is not on the text field itself, but on a containing table or something like that. Make sure the element located by the id is the input, so the sendKeys will work.
By
In the text box it is fetching the value but it can't able not store
in the text box field
do you mean you can see selenium typing those values into the textbox and then the values disappear?
If that is what is happening, it is possible there is some javascript running on the page while selenium is entering the values in the textbox. you can try to put a wait before selenium enters the value. If waiting resolves the issue, you will need to write a method to detect when the javascript is done.

How to catch one specific text from html source code using Jsoup?

I tried the solution from:
How to extract text of paragraph from html using Jsoup?
jsoup how to extract this text
but both examples are working with texts from tags.
I have this unique piece of code on my html web search:
and what I need is to take the link that comes with the d.href variable.
I tried codes like:
Elements link = jSoupConnection.select(":contains(d.href)");
Elements link = jSoupConnection.select("#d.href");
Elements link = jSoupConnection.getElementsByAttributeValueContaining("d.href","google");
but until now none of them worked.
I tried also to make one research at http://jsoup.org/cookbook/ and also nothing sucessfull. Could anyone more experienced with Jsoup help me please??
Thanks in advance
In case of your text doesn't come with any tag that you could specific catch with Jsoup select elements, you should download the hole page (which you can do with Elements link = jSoupConnection.select("*");) and then open it on your application as one text file to retrieve whatever you want. If the downloaded file is too big, and that was my problem, try to limit the file size download; more details you can find on those links:
Limiting file size creation with java
How to limit the file size in Java

Display a scrolling message that can be updates by another webpage

I'm looking for a solution to this and I have searched the web for an answer with nothing. I need a scrolling message on my webpage that can be updated by the same website but on a different page. (e.g www.webpage.com <-- has the scrolling message on it, www.webpage.com/settings <-- has a form in which you can change/update the scrolling message)
I'm pretty sure this is achievable with Java, but my knowledge on Java is slim and all my efforts have come to a fail. I have managed to get a scrolling message on my webpage and I'm sure if I could read a text file (with the message in) then assign that to a 'var', I could make that scroll but I don't know how to do that.
If you know a completely different method of doing this I am happy to change mine.
Thanks in advance,
Tom.
I would recommend javascript instead of java, since java is not really conventional anymore and looks ugly too (and requires a special plugin).
It depends on how fast you want to update the scrolling text how you want to do this. I would say save the text to a .txt or database from settings, and then have your page get it.
You can then use php to read the value from the .txt file or database to display it on your website.
If you want it to be extremely up to date you can let javasript call a little .php file that reads the file and gives you the content.
To make your text scroll you don't really need anything other than html, like so:
<marquee behavior="scroll" direction="left">Your scrolling text goes here</marquee>
You can read more about that here: http://www.quackit.com/html/codes/scrolling_text.cfm

Categories