0

How can I get the value from this element:

<div time="1582408800000" title="" class="day toMonth  valid real-today checked first-date-selected">23</div>

I have tried the following:

//web.getAttribute('//div[@class="day toMonth  valid real-today"]', div)

var bsaleDate = web.getValue('//div[@class="day toMonth  valid real-today"]');

I'm trying to get the 23 as a value and insert it into a variable. I am using Oxygen IDE which is based on JavaScript.

2
  • 2
    <div> elements don't have a "value". You're looking for .textContent probably. Commented Feb 23, 2020 at 12:48
  • I don’t think time is a valid attribute on a div Commented Feb 23, 2020 at 13:03

3 Answers 3

1

You could use DOM selector to select the element and then get the content.

Note that div element doesn't has the value attribute, Div element could hold html or text content.

To get the html content we could use innerHTML attribute. And to get text we could use textContent attribute

I am using document.querySelector to select the element with the help of css selector.

(function() {
    let ele = document.querySelector('.first-date-selected');
    console.log(ele.textContent);
})()
<div time="1582408800000" title="" class="day toMonth  valid real-today checked first-date-selected">23</div>

Sign up to request clarification or add additional context in comments.

Comments

0

You need to use the getElementsByClassName method to get all the elements of specific class.

var x = document.getElementsByClassName("day");

IF you want to Get all elements with "day toMonth valid real-today checked first-date-selected" classes, you can just use below statement.

var x = document.getElementsByClassName("day toMonth valid real-today checked first-date-selected");

alert(x[0].innerText);

Hope this could solve your problem.

Comments

0

by value if you meant '23' is what you wanted. Then you can use getText().

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.