question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] How to select vue component's data property

See original GitHub issue

I have a slider element QSlider which has data -> model equal to 8. I have selected the component using

sliders = page.query_selector_all("_vue=QSlider")
sliders[0]

but not sure how can I get model value and modify it. Would appreciate any kind of help thanks

Screenshot 2022-01-20 at 3 25 26 AM

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
aslushnikovcommented, Jan 27, 2022

The goal here is to be able to have access to a DOM element to check some of its properties. Analogous to doing something like this:

@protozoo You can do this already using locator.evaluate:

const handle = page.locator(`_vue=QSlider`);
const isGood = await handle.evaluate(myVueEnabledDOMElement => {
  let elementVueInstance = myVueEnabledDOMElement.__vue__;
  let checkedPropertyValue = elementVueInstance.counter;
  return checkedPropertyValue == expectedValue;
});

As far as I understand, this should address your needs!

2reactions
protozoocommented, Jan 20, 2022

Extendig @AbhimanyuAryan 's question: The goal here is to be able to have access to a DOM element to check some of its properties. Analogous to doing something like this:

function checkVueElementProperty(){
  let expectedValue = 55;
  let myVueEnabledDOMElement = document.getElementById( "myComponentX" );
  let elementVueInstance = myVueEnabledDOMElement.__vue__;
  let checkedPropertyValue = elementVueInstance.counter;
  return checkedPropertyValue == expectedValue;
}

So, in summary, how to get “direct” access to a DOM element and then to its JS properties. This isn’t necessarily restricted to Vue cases, although in our case we are interested in testing Vue components internal state.

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I pass a data attribute in vue js select option
I need to pass a select object data attribute ...
Read more >
Select component — Vuetify
Select fields components are used for collecting user provided information from a list of options. # Usage ...
Read more >
Rendering a list of Vue components - Learn web development
First we need to get an array of to-do items. To do that, we'll add a data property to the App.vue component object,...
Read more >
Vue.js Form Input Binding with Select option - GeeksforGeeks
Step 2: In the App.vue file, add the data members, category, and language for the v-model modifier. Vue.js will store the single select...
Read more >
How To Generate a Vue.js Single Page App With the Vue CLI
Choose a version of Vue.js that you want to start the project with 2.x ❯ 3.x (Preview). The next question is regarding TypeScript ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found