Simulate Click with webview on a href

Asked

Viewed 124 times

2

<li class="paginate_button page-item next" id="tb_next"
  <a href="#" aria-controls="tb" data-dt-idx="5" tabindex="0" class="page-link">Seguinte</a>
</li>

Hello friends, I have a page that has this html code and I need to simulate a click on this href, the simulation I already get via webview (javafx)

webEngine.executeScript(
  "document.getElementById(\"botão\").click();"
);

But as you can see there is only ID in the parent element and then I am not able to access the href child element.

I tried it like this, but it’s not working:

webEngine.executeScript(
  "document.getElementById(\"tb_next\").firstChild.click();"
);

Could someone help me please, I already appreciate any help.

2 answers

0

Use document.querySelector where you can more easily select the <a> within the <li> in question:

document.querySelector("#tb_next a").click();

Example:

document.querySelector("#tb_next a").click();
<li class="paginate_button page-item next" id="tb_next">
   <a href="javascript: alert('ok')" aria-controls="tb" data-dt-idx="5" tabindex="0" class="page-link">Seguinte</a>
</li>

  • Obg Friends, for the ready help, but would have some solution done in javascript, I do not know why but my program is not able to run Jquery.

  • see the error msgs: Typeerror: Document.querySelectorAll("#tb_next > . page-link"). click is not a Function. (In 'Document.querySelectorAll("#tb_next > . page-link"). click()', 'Document.querySelectorAll("#tb_next > . page-link"). click' is Undefined) Typeerror: null is not an Object (evaluating 'Document.querySelector("#tb_next a"). click')

  • Friend, my answer does not use jQuery. I believe that the other answer is incorrect.

-1

I do using the querySelectorAll

the ex of selection would be something like this

webEngine.executeScript(
  "document.querySelectorAll(\"#tb_next > .page-link\").click();"
);

it would click on all .page-link that they have within a #tb_next

Browser other questions tagged

You are not signed in. Login or sign up in order to post.