【发布时间】:2018-02-28 10:45:32
【问题描述】:
我希望单击此 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>
【问题讨论】:
-
html的哪一部分发生了变化?
class内的<div>属性?它变成了什么?也许有一些静态部分可能需要寻找? -
你能用更多的 outerHTML 更新问题吗?
-
你不能给div一个固定的id吗?您可以通过 id 检索,通常这是固定元素的最佳选择。