Skip to main content

Protractor getText from hidden element.

Ran across a point that I wanted to get the value of a hidden element while running my Protractor tests. getText() function was not helpful at all. In order for it to return text it has to be visible. There is an option called getAttribute('textContent'). This will allow you to always return the text.

Sample HTML

<span style="display: none" name="hiddenSpan">Hidden Text</span>

Sample Protractor JS

$('[name="hiddenSpan"]').getText();
// returns ""
$('[name="hiddenSpan"]').getAttribute('textContent');
// returns "Hidden Text"

Comments

Popular posts from this blog

Reverse a number without converting to a string.

Sometimes I like to work on coding problems just for fun. Things like Project Euler, Code Eval Hackerrank etc. Depending on what language you decide to do things in it might be easier and more efficient to think a little different. Some languages like Ruby, for example, converting a number to a string with to_str() and then reversing is rather trivial. But what if I want to solve it by keeping the number a number? Currently, I am playing around with Rust so my example will be in that language however you can use this same formula in whatever language you like. pub fn num_reverse(number: i32) -> i32 { let mut num = number; let mut rev = 0; while num > 0 { rev = rev * 10 + (num % 10); num = num / 10; } return rev; } Now that we have the code lets map out a little bit of how it works. Let us take the number 1234. num = 1234; rev = 0; Grab the first digit. rev = rev * 10 + (num % 10) Which can be written as. rev = 0 * 10 ...

High Sierra and Valgrind Install

Valgrind is a tool used for memory management and profiling your applications.  I wanted to use it on my Macbook and ran into issues installing with brew and it turned out it wasn't too horrible of a change. brew update brew install --HEAD valgrind    Voila you now have a working run of valgrind. Happy Trails.

Javascript - Rounding numbers to decimal

function roundNumber(number, decimal) { return Math .round(number * Math .pow( 10 , decimal)) / Math .pow( 10 , decimal); } How it works The first thing to understand is how the Math.round() function works in Javascript. The round function takes what ever number that it is given and strips off everything after the decimal point. So if you have a number like 343.12345678 it will return 343. For this example lets say you want to have 2 decimal points left for your output like 343.12. To get the decimal points that we want we need to move the decimal point over 2 spots so that they will not be removed from the round function. Each decimal place is a factor of 10. Tenths, Hundredths, Thousandths, etc. Lets now multiply 343.12345678 by 10^2. 10 is the decimal and the 2 is how many we need to move. You should get 34312.345678. Now if you use the round function you will get 34312 right? So now that we have all the correct numbers we need to get the number back to the right value...