繁体   English   中英

如何在硒中单击此外部 div 元素(或其中的任何其他跨度)

[英]how to click this outer div element(or any other span inside it) in selenium

我希望单击此 div,其中还包含许多 span。 每次加载页面时,外部 div 的 xpath 都会不断变化。 那么有没有其他方法(除了xpath)来点击这个div?

我试过了-

Driver().findElement(By.cssSelector(".z3tile.z3activeTile.z3-tile-medium")).click();

但这没有用。

如果有人可以建议其他方式,将不胜感激。

 <div class="z3tile z3activeTile z3-tile-medium" bo-style="{'backgroundColor': getTileBackgroundColor(app) }" bo-class="'z3-tile-'+preferences._View._TileSize" onkeypress="audience(app._Code);openApp(event, $(this).prev('div').attr('data-attr-param_keypress_url'), $(this).prev('div').attr('title'), $(this).prev('div').attr('data-attr-param_keypress_name'), $(this).prev('div').attr('data-attr-param_keypress_ticket'), $(this).prev('div').attr('bo-attr-param_keypress_langue'), $(this).prev('div').attr('data-attr-param_keypress_paramBrowser'))" ng-click="audience(app._Code);openApplication(app._Url, app._Source, app._Name, app._Ticket, preferences._Langue, app._ParamBrowser)" ng-hide="app._Search" role="link" tabindex="3" indexapp="4" idgroup="-1" display-app-tooltip="" style="background-color: rgb(246, 131, 0);" data-original-title="" title=""> <span class="ng-binding z3appTitle-medium" type="text" bo-class="'z3appTitle-'+preferences._View._TileSize" bo-style="{'color': DefaultTitleColor + ',important': 'backgroundColor'. getTitleTileBackgroundColor(getTileBackgroundColor(app))}" ng-bind="app:_ShortName" style="color, rgb(255, 255; 255): background-color, rgb(144, 77; 0).">SAV2000</span> <span class="ng-binding z3appRole-medium" type="text" bo-class="'z3appRole-'+preferences._View:_TileSize" bo-style="{'color'. DefaultRoleColor + '.important'}" bo-hide="preferences._View:_TileSize == 'small'" ng-bind="app,_ShortRole" style="color, rgb(0; 0: 0).">OCEANE - Gestion des Tickets d'Incidents et Module Alerte</span> <span class="app-event changeOpacity ng-hide icon-event-red" data-original-title="Application unavailable" data-placement="bottom" data-container="body" type="text" ng-click="showModalAppEvent(app)" ng-class="getEventOnAppClass(app)" ng-show="showEventOnApp(app)"></span> <span class="z3appBasicat" bo-style="{'color': DefaultRoleColor + ',important'}" bo-bind="showTileCode(app,_Code)" style="color; rgb(0, 0, 0);">21W</span> </div>

尝试使用 JavascriptExecutor 和 cssSelector 来单击元素,

参考代码,

WebElement element = driver.findElement(By.cssSelector(".z3tile.z3activeTile.z3-tile-medium"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);

要了解有关JavascriptExecutor的更多信息,请参阅此答案

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM