2

I've been working on a web UI automation task with Selenium, Javascript and SeLion. I would like to take a screenshot of some equivalent scenario as Google homepage below: enter image description here

In which the "Search by voice" should be present when mouse moves in that microphone icon (neither Click or Hover). I have search bunch of solutions, unfortunately non of them works as expected.

I'm basically dealing with something like this:

<div id="div_id">
  <button type="button" class="button_class" disabled="" data-marko=" . 
    {"onclick":"handleClick s0-2-0-27-0 
    false&quot;,"onkeydown":"handleKeydown s0-2-0-27-0 false"}" 
    title="This message shows by mouseenter event" aria-label="This 
    message shows by mouseenter event">
      <span class="span_class"></span>
  </button>
</div>

When mouse enters that button, "This message shows by mouseenter event" will be present. The page is likely written by Marko-js. Couldn't really handle it with plain Javascript, I tried.

Any idea?

Thanks in advance!

Almett
  • 876
  • 2
  • 11
  • 34

2 Answers2

0

In which the "Search by voice" should be present when mouse moves in that microphone icon (neither Click or Hover)

if u read this link : https://www.w3.org/TR/DOM-Level-3-Events/#trusted-events , it says that only user agent events can trigger "search by voice" . its cant be done by scripts

SoroushNeshat
  • 656
  • 5
  • 11
0

I provided you a simple working example, give me a feedback if it is suitable for your needs.

function simulateMouseEnter() {
  var event = new MouseEvent('mouseenter', {
    'view': window,
    'bubbles': true,
    'cancelable': true
  });
  var myTarget = document.getElementById('target_div'); 
  var canceled = !myTarget.dispatchEvent(event);
  if (canceled) {
    // A handler called preventDefault.
    alert("canceled");
  } else {
    // None of the handlers called preventDefault.
    alert("not canceled");
  }
}

function mouseEnterBehaviour() {
    myElement = document.getElementById("target_div");
     // attach mouseenter event listener to element
    myElement.addEventListener("mouseenter", function(event) {
        // change the color of the font
        event.target.style.color = "red";
    });  
    // call the simulation
    setTimeout(simulateMouseEnter,3000);
}

mouseEnterBehaviour();
<div id="target_div">target div</div>

Note: this should work with the most of the browser events

Mosè Raguzzini
  • 15,399
  • 1
  • 31
  • 43
  • Thanks for your effort. This code works perfectly but not in my scenario. I've added some details in my question, please take a look. Thanks – Almett Sep 14 '18 at 11:36