0

I want to change css style of a line in browser. For example. i have a div

<div class="slider" style="top: 0px; left: -18px;">

Now i want to change it to

<div class="slider" style="top: 200px; left: -18px;">

How can i do it by JxBrowser?

Thank you so much!

  • Right now JxBrowser DOM API doesn't provide functionality that allows modifying css style attributes. You can try changing them using JxBrowser DOM API that allows working with DOM element attributes: https://jxbrowser.support.teamdev.com/support/solutions/articles/9000013710-element-attributes – Vladimir May 04 '16 at 10:05

1 Answers1

0

You can certainly make CSS modifications, but the elements that you want to modify need to have some distinct identifier so that you can access them via JS injection. This would be a class,'data-value' attribute or an id that is unique to the element or group of elements that you want to modify. If you have that, then you can use something like:

String jsString = "document.getElementsByClassName('slider')[0].style.left='33px';";
Browser.executeJavaScript(jsString);

Functions should wrapped in a JS setTimeout(), onload() or something like a Java TimerTask if you want to ensure that the page is completely loaded first.

There are also limits to what can be done. For example, I haven't found a way to add a full stylesheet block (with filters) to an existing page, but smaller changes are relatively easy.

SilentStone
  • 537
  • 5
  • 10