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

问题描述 投票:0回答:1

我希望点击这个div,它还包含很多跨度。每次加载页面时,外部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>
java html selenium
1个回答
-1
投票

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

参考代码,

WebElement element = driver.findElement(By.cssSelector(".z3tile.z3activeTile.z3-tile-medium"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
© www.soinside.com 2019 - 2024. All rights reserved.