我正在使用Selenium和Java测试电子邮件提供商,但我无法点击所选元素。我尝试过使用XPath,CSS等没有成功。在这种情况下,id是动态的。
有人可以帮我解决这个问题吗?
<iframe id="r859306833.2009263" class="application mail display_enabled focus" frameborder="0" src="https://3c-bs.gmx.com/mail/client/start;jsessionid=CA1C516E76A9E31DCBE654A3BEFC91FE-n2.bs12b?uc=SUCCESS&navigator_theme=intenseblue&navigator_bg=intenseblue#yclujpsz" name="mail" allowfullscreen="true" mozallowfullscreen="" webkitallowfullscreen="" allowtransparency="true">
<!DOCTYPE html>
<html id="html-tag" class="windows gecko ff ff40 page-homepage theme-intenseblue themegroup-unifiedintenseblue iac can-have-sky can-have-adb js postmessage history cssanimations localstorage plugin-pdf-inline sky-320 rect-480 no-adb" lang="en-US">
<head>
<body class="app" style="cursor: auto;">
<h1 class="accessibility" role="contentinfo">
<div id="js-colorpicker">
<div id="id2cb" class="page js-component" data-component-callback-url="./home;jsessionid=CA1C516E76A9E31DCBE654A3BEFC91FE-n2.bs12b?11-1.IBehaviorListener.0-page&navigator_theme=intenseblue&navigator_bg=intenseblue&folderId=tfol1406b7f6f764374e" data-component="BasePage">
<div id="blocker" style="display: none;"></div>
<div class="page-body">
<div id="id2cc" class="ad sky" data-type="sky" data-url="//mailderef.gmx.com/adimg.uimserv.net/mailcom/generic.htm?site=gmxcom§ion=en/freemail/3cmail_fm/folder/inbox®ion=&category=mail&categorytype=mail&pg=m&pa=22&pp=__NULL&userlevel=freemail&cn=mx&ssl=true&edition=en&position=atf&addiv=div-ad&tagID=sky" data-maxwidth="320">
<div id="section-0" class="section-container section-0 js-box-vertical section">
<div id="id2cd" class="navigation-container-top" data-stage="{"val":0,"id":"navigation-drafts"}">
<div class="panel panel-composition">
<div class="button-group-firstblockbutton js-component button-group" data-component="ButtonGroup">
**<a id="id2aa" class="button-block m-button button-cta button-link button-size-large js-component" data-component="ButtonLink" title="Compose E-mail" href="javascript:;">Compose E-mail</a>**
<div class="button-group-firstblockbutton_subgroup"> </div>
</div>
</div>
</div>
<div class="scroll has-num-panel-links-2">
<div class="navigation-container-bottom">
</div>
<div class="section section-content section-1">
</div>
</div>
<div id="id30b">
<div id="uploadContainer"></div>
<script src="//js.ui-portal.de/apps/shared/jquery/1.8.3/jquery-1.8.3.min.js" type="text/javascript">
<script src="https://sec-s.uicdn.com/3c-cdn/mail/client/wicket/resource/static-res/---/js/core-vEr-6135656366653934.js" type="text/javascript">
<script id="wicket-ajax-base-url" type="text/javascript">
<script src="https://sec-s.uicdn.com/3c-cdn/mail/client/wicket/resource/static-res/---/js/jqueryui-vEr-6630336635343631.js" type="text/javascript">
<script src="https://sec-s.uicdn.com/3c-cdn/mail/client/wicket/resource/static-res/---/js/behavior-vEr-3763623264316262.js" type="text/javascript">
<script id="mailListClickDelegate" type="text/javascript">
<script src="//js.ui-portal.de/apps/navigator-common/iac/client/3.1.0/iac.client-3.1.0.min.js" type="text/javascript">
<script src="//js.ui-portal.de/c/eic/eic.js" type="text/javascript">
<script src="//js.ui-portal.de/apps/navigator-common/iac/eic.iac.mapping.min.js" type="text/javascript">
<script src="https://sec-s.uicdn.com/3c-cdn/mail/client/wicket/resource/static-res/---/js/external-vEr-6136373566653261.js" type="text/javascript">
<script type="text/javascript">
<script type="text/javascript">
</body>
</html>
</iframe>
答案 0 :(得分:3)
我很确定这只是因为存在iframe
。
切换到它,然后尝试找到所需的元素:
driver.switchTo().frame("mail"); // switch to the context of the iframe
driver.findElement(By.linkText("Compose E-mail")).click();