$(selector).click()
results in nothing happening.
this answer works in the browser console with the javascript context set to the iframe, but not the main page:
simulateMouseClick($("iframe").contents().find(selector))
results in:
Uncaught TypeError: targetNode.dispatchEvent is not a function
at triggerMouseEvent (:5:20)
at :8:9
at Array.forEach ()
at simulateMouseClick (:7:52)
at :1:1
$("iframe").contents().find(selector).text()
gives me what's expected so it's the correct element.
how can I achieve this?
Edit: adding this as people apparently can't read:
$("iframe").contents().find(selector).click()
has absolutely no effect as .click()
does not simulate a REAL mouse click.
$(selector).click()
results in nothing happening.
this answer works in the browser console with the javascript context set to the iframe, but not the main page:
simulateMouseClick($("iframe").contents().find(selector))
results in:
Uncaught TypeError: targetNode.dispatchEvent is not a function
at triggerMouseEvent (:5:20)
at :8:9
at Array.forEach ()
at simulateMouseClick (:7:52)
at :1:1
$("iframe").contents().find(selector).text()
gives me what's expected so it's the correct element.
how can I achieve this?
Edit: adding this as people apparently can't read:
$("iframe").contents().find(selector).click()
has absolutely no effect as .click()
does not simulate a REAL mouse click.
2 Answers
Reset to default 2With jQuery :
$("iframe").contents().find(selector).click();
With Vannila JS :
Using window.frames gives you access to the iframes' window object, as mentionned in the Mozilla doc
You can use this object to find elements in the iframe and use them in your script. For example :
var iframeWindow = window.frames[0];
var element = iframeWindow.document.getElementsByClassName("selector")[0];
element.click();
Get the element inside your jQuery Object, and use the vanillaJS .click()
method:
$("iframe").contents().find(selector)[0].click();
That's it.
PS: I know this is an old question, but I had the same problem and solved it that way :)
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744903295a4600105.html
评论列表(0条)