1

I'm trying to use the selenium chrome driver on Java and part of my script requires me to edit a google chrome element of a website.

How can I modify the value of this element using java?

I figured out I'm supposed to use this code:

JavascriptExecutor js = (JavascriptExecutor) driver;

js.executeScript("script here");

But I'm not sure what to put in the js.executeScript part? I'm pretty sure its javscript but I'm unfamiliar with javascript and could not figure out how to edit this element using it.

This is the element in attempting to change:

Element is circled

What would be the javascript line that could change that circled element?

If you need any further information I would be glad to provide it.

matisetorm
  • 857
  • 8
  • 21
Blake W
  • 33
  • 1
  • 1
  • 6

1 Answers1

0

You can select the element in this way and then modify it in the way you want. Unless you mention what modification, this is how you can get the element.

var element = document.querySelector('[data-productid="505595887"]')

document.querySelector('[data-productid="505595887"]') is the js code you need to execute.

  • How can I set it to be a number like "50" instead of "505595887"? – Blake W Dec 27 '17 at 04:39
  • use this code to set ti 50 or any value: document.querySelector('[data-productid="505595887"]').setAttribute("data-productid","50") –  Dec 27 '17 at 04:45
  • Check this [question](https://stackoverflow.com/questions/8473024/selenium-can-i-set-any-of-the-attribute-value-of-a-webelement-in-selenium) – himawan_r Dec 27 '17 at 04:47