Copy Text From a Web Page Text Field Into a Variable

Hi!

I'm struggling with a quite simple task:

On a HTML page (Chrome) there is a text field I like to copy the text into a variable and use it later.

<p class="form-field _billing_email_field ">
<label for="_billing_email">E-postadresse</label><input type="text" class="short" style="" name="_billing_email" I'd="_billing_email" value=“user_email@Gmail.com" placeholder=""> </p>

It’s the value “user_email@Gmail.com” I like to store in a variable.

I have tried all of the following:

Copy JS path:
document.querySelector("#_billing_email")

Copy xpath:
//*[@I'd="_billing_email"]

Copy full xpath:
/html/body/div[1]/div[2]/div[3]/div[1]/div[5]/form/div[2]/div/div[3]/div[1]/div[1]/div[2]/div/div/div[1]/div[2]/div[2]/p[10]/input

Writing to the same fields is no problem...

Best regards
Lars

"Whoever said that the definition of insanity is doing the same thing over and over again and expecting different results has obviously never had to reboot a computer."

Hey Lars,

Try

document.querySelector("#_billing_email").value

OR

document.querySelector("#_billing_email").innerText

If you try this the console of Safari or Google Chrome you can paste:

document.querySelector("#_billing_email").<-- Note the dot

When you type the dot, the editor will give you the available parameters.

-Chris

-Chris

1 Like

Thank you ccystone!

This worked:

document.querySelector("#_billing_email").value

Best regards

1 Like