任何人都可以帮助我如何匹配此元素,我想从国家/地区列表中单击加拿大。 Selenium(IDE / WebDriver)没有找到该元素。 我试过Webdriver:
driver.FindElement(By.XPath(".//*[@class='slick-viewport']/*[@class='grid-canvas']/*[@class='ui-widget-content slick-row odd']/*[@class='slick-cell l1 r1 active selected']")).click();
Firepath提供此XPath:
.//*[@id='assetsTable']/div[5]/div/div[5]/div[2]
这些都不起作用。显然,我做得不对。 id是动态生成的,并且是嵌套的,所以我发现它很难解决。任何人都可以看看并告诉我正确的定位方式吗?
非常感谢
PS:看起来我不允许上传图片。所以,复制粘贴下面的内容:
<!DOCTYPE html>
<html class="dj_gecko dj_contentbox">
<head>
<body id="bodyID">
<div id="pageDiv" class="page">
<div id="header">
<div id="main">
<ul id="mainMenu" class="menuTab">
<div id="partialHost" style="height: 345.117px;">
<div id="assetsBreadcrumbDiv">
<div id="assetsGridDiv">
<ul id="assetMenu" class="menuTab">
<div id="assetsTable" class="defaultGrid slickgrid_109601 ui-widget" style="overflow: hidden; outline: 0px none; position: relative; height: 269.117px; width: 1562px;">
<div style="position:fixed;width:0;height:0;top:0;left:0;outline:0;" hidefocus="" tabindex="0"></div>
<div class="slick-header ui-state-default" style="overflow:hidden;position:relative;">
<div class="slick-headerrow ui-state-default" style="overflow: hidden; position: relative; display: none;">
<div class="slick-top-panel-scroller ui-state-default" style="overflow: hidden; position: relative; display: none;">
<div class="slick-viewport" style="width: 100%; overflow: auto; outline: 0px none; position: relative; height: 242px;">
<div class="grid-canvas" style="width: 1545px; height: 5975px;">
<div class="ui-widget-content slick-row odd" style="top:775px">
<div class="ui-widget-content slick-row even" style="top:800px">
<div class="ui-widget-content slick-row odd" style="top:825px">
<div class="ui-widget-content slick-row even" style="top:850px">
<div class="ui-widget-content slick-row odd" style="top:875px">
<div class="slick-cell l0 r0 selected">CA</div>
<div class="slick-cell l1 r1 active selected">CANADA</div>
<div class="slick-cell l2 r2 selected">Y</div>
<div class="slick-cell l3 r3 selected"></div>
<div class="slick-cell l4 r4 selected">CA</div>
</div>
<div class="ui-widget-content slick-row even" style="top:900px">
<div class="ui-widget-content slick-row odd" style="top:925px">
<div class="ui-widget-content slick-row even" style="top:950px">
答案 0 :(得分:3)
// div [text()=“CANADA”]应该有效。如果你只想要那个特定的元素。
答案 1 :(得分:0)
不要使用*,在XPath查询中显式。
这有效:
//div[@class='slick-cell l1 r1 active selected']
直接在FireBug中尝试XPath查询后会得到什么?