admin管理员组文章数量:1356595
I want to be able to click on Agree button to give my consent for cookies on a website, I know how to do this in selenium webdriver, however, I have no idea on how to do this using js and mocha as I am trying to learn any help is appreciated.
I tried
browser.switchToFrame($('#sp_message_iframe_207015'));
$(getHighlightedText('Agree')).click();
But no use
Basically, I launch the site and I get a popup asking to Agree cookies and manage cookies/preferences, I just want to be able to click on Agree
#sp_message_iframe_207015
is the Id of the Iframe
Agree element looks like this
<button
tabindex="0"
title="Agree"
aria-label="Agree"
class="message-ponent message-button no-children"
path="[0,4,1]"
style="padding: 10px 50px; margin: 10px; border-width: 1px; border-color: rgb(0, 115, 197); border-radius: 20px; border-style: solid; font-size: 14px; font-weight: 600; color: rgb(255, 255, 255); font-family: "trebuchet ms", helvetica, sans-serif; width: auto; background: rgb(0, 115, 197);"
>
Agree
</button>
I want to be able to click on Agree button to give my consent for cookies on a website, I know how to do this in selenium webdriver, however, I have no idea on how to do this using js and mocha as I am trying to learn any help is appreciated.
I tried
browser.switchToFrame($('#sp_message_iframe_207015'));
$(getHighlightedText('Agree')).click();
But no use
Basically, I launch the site and I get a popup asking to Agree cookies and manage cookies/preferences, I just want to be able to click on Agree
#sp_message_iframe_207015
is the Id of the Iframe
Agree element looks like this
<button
tabindex="0"
title="Agree"
aria-label="Agree"
class="message-ponent message-button no-children"
path="[0,4,1]"
style="padding: 10px 50px; margin: 10px; border-width: 1px; border-color: rgb(0, 115, 197); border-radius: 20px; border-style: solid; font-size: 14px; font-weight: 600; color: rgb(255, 255, 255); font-family: "trebuchet ms", helvetica, sans-serif; width: auto; background: rgb(0, 115, 197);"
>
Agree
</button>
Share
Improve this question
edited Jan 24, 2021 at 14:50
juliomalves
50.6k23 gold badges178 silver badges169 bronze badges
asked Jan 23, 2021 at 21:52
sitaramsitaram
611 gold badge1 silver badge6 bronze badges
1
-
not sure what is
getHighlightedText
in your code. It's a bit difficult to guess without details like WebdriverIO version you have and the website you use. – Mike G. Commented Jan 25, 2021 at 15:05
2 Answers
Reset to default 5Thanks all
I have managed to get it working with the following
let frame= browser.$('#sp_message_iframe_207015');
browser.pause(5000);
browser.switchToFrame(frame);
browser.setTimeout({ 'implicit': 10000 })
let clickAgree = $('button[title="Agree"]');
clickAgree.click();
browser.switchToParentFrame();
The scenario is like following:
- Make sure the iframe exist
- Switch to iframe with browser.switchToFrame
- If there are nested iframe(s) repeat steps 1 - 2
- Look for an element within iframe
As far as I have no access to your app, let imagine the DOM structure
body
h1
iframe id="main"
h2
<button title="Agree">Agree</button>
div
// switch to iframe
const mainIframe = $('#main')
expect(mainIframe).toExist()
browser.switchToFrame(mainIframe)
// interact with element within iframe
const agreeButton = $('button[title="Agree"]')
expect(agreeButton).toBeClickable()
agreeButton.click()
// switch back to parent frame
browser.switchToParentFrame()
Here is an example of accepting cookies and switching to iframe using webdriverio browser object how to check video is playing or not
本文标签: javascriptHow to handle Iframe content using webdriverIO js and mochaStack Overflow
版权声明:本文标题:javascript - How to handle Iframe content using webdriverIO js and mocha - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744066259a2585053.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论