Jacek Góraj Jacek Góraj - 1 year ago 131
HTML Question

how to get float value from element?

I can't find answer to my problem. I need to get value 0.01 from below and then operate with it, eg. add some value etc.

Let's say we have an HTML:

<div>Exchange rate</div>

So the xpath is

„//div[text() = ‘Exchange rate’]/../span”

In protractor I manage to create element variable:

var element = element(by.xpath(„//div[text() = ‘Exchange rate’]/../span”));

Now I need to get float value from it and use it later in code.

How can I do it?

Answer Source

To start with, your html is non-angular and using 'element' will throw you errors. I am not sure if the code snippet is just an example and if you are actually operating on angular pages, so I will answer both cases

For Non-Angular case:

browser.driver.get("<<>>/test.html"); browser.driver.findElement(by.xpath('//span')).getText().then(function(value){ console.log("The Float value is " + parseFloat(value)) });

For Angular pages:

        console.log("The Float value is " + parseFloat(value))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download