我想从html中获取元素
<div style="width: 100%; height: 100%; cursor: url(""), default;" class="yfiles-canvascontrol" tabindex="1"><div style="bottom: 0px; right: 0px;" class="yfiles-svgpanel"><div style="position:absolute;top:0;left:0;height:100%;width:100%;"><svg style="position:absolute;top:0;left:0;height:100%;width:100%;pointer-events:none"><g transform="translate(348.5, 128.5)" style="pointer-events:visiblePainted"><g transform="translate(75 175)" class="aw-relations-groupNodeSvg aw-relations-detailLevel0">
<rect stroke="rgb(191,161,229)" class="aw-widgets-cellListItemNode" height="125" width="300" transform="translate(0 0)"></rect>
<rect stroke="rgb(191,161,229)" class="aw-relations-noeditable-area" height="125" width="300" transform="translate(0 0)"></rect>
<rect stroke="rgb(191,161,229)" class="aw-relations-noeditable-area" height="125" width="300" transform="translate(0 0)"></rect>
<rect stroke="rgb(191,161,229)" height="125" width="300" class="aw-relations-seedNodeSvg" transform="translate(0 0)"></rect>
<rect height="125" width="300" class="aw-relations-noeditable-area" transform="translate(0 0)"></rect>
<g>
<rect fill="rgb(191,161,229)" height="" width="10" transform="translate(0 0)"></rect>
<line stroke="rgb(191,161,229)" y2="" x2="300" y1="" x1="0"></line>
<g transform="translate(65)">
<g id="header">
<g class="" transform="translate(0 20)">
<rect fill="none" height="28px" width="230px" transform="translate(0 0)"></rect>
<text transform="translate(0 21)" ontouchstart="onEditLabelClicked(this)" onclick="onEditLabelClicked(this)" onmouseout="onEditLabelMouseOut(this)" onmouseover="onEditLabelMouseOver(this)" data-id="SR::N::Ase0LogicalElement..Fnd0LogicalBOMLine..5.6ZarDeTC8VoL5B.J$vlO1AI8VI9qC.Group:/Thid_wCYVM0YsoaNeFC,,AWBCB" data-width="100%-80" data-property-name="awb0ArchetypeRevName" class="aw-widgets-cellListCellTitle" id="title">block1</text>
</g>
<g transform="translate(0 46)" data-translate-top="title">
<text transform="translate(0 13)" ontouchstart="onEditLabelClicked(this)" onclick="onEditLabelClicked(this)" onmouseout="onEditLabelMouseOut(this)" onmouseover="onEditLabelMouseOver(this)" data-id="SR::N::Ase0LogicalElement..Fnd0LogicalBOMLine..5.6ZarDeTC8VoL5B.J$vlO1AI8VI9qC.Group:/Thid_wCYVM0YsoaNeFC,,AWBCB" data-width="100%-80" data-property-name="ID" class="aw-widgets-cellListCellItemType" id="subTitle">000444</text>
</g>
<g transform="translate(0 63)" data-translate-top="subTitle">
<text class="aw-widgets-cellListCellPropertyValue" transform="translate(0 15)">Revision: A</text>
</g>
</g>
<g transform="translate(0 93)" data-translate-top="subTitle" data-translate-y="30">
<g ontouchstart="runCommand(this)" onclick="runCommand(this)" data-commandid="com.siemens.splm.client.relations.internal.commands.expandincoming" data-contextmenu="" data-tooltip="Show Incoming Relations" data-id="SR::N::Ase0LogicalElement..Fnd0LogicalBOMLine..5.6ZarDeTC8VoL5B.J$vlO1AI8VI9qC.Group:/Thid_wCYVM0YsoaNeFC,,AWBCB" class="hidden" transform="translate(0 0)">
<rect class="hidden" height="22px" width="22px" transform="translate(0 0)"></rect>
<image xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAWCAYAAADEtGw7AAAApklEQVR42mNgGCxg6tSpBkCcQHWDJ0+e7DBlypT/QLqBJgZD8XxaGQzC+/v7+wVoYTAIn58+fboCMRG0HotmQvg9KGLxGgzyHhkGgw0H+iiAFgaDMc5gocRgvGmcTINBweBAThjPh6aIArIiDpfBsJyGJbmdJzodE2swKFmSlDmINHg+MbmpARkDNd0nYHABsS4kGOtklWajBqOnApwYlKyIKhbpAQDnZhqtR8K2hAAAAABJRU5ErkJggg==" height="22px" width="22px" transform="translate(0 0)"></image>
<text class="hidden" transform="translate(22 15)">0</text>
</g>
<g ontouchstart="runCommand(this)" onclick="runCommand(this)" data-commandid="com.siemens.splm.client.relations.internal.commands.expanddown" data-contextmenu="" data-tooltip="" data-id="SR::N::Ase0LogicalElement..Fnd0LogicalBOMLine..5.6ZarDeTC8VoL5B.J$vlO1AI8VI9qC.Group:/Thid_wCYVM0YsoaNeFC,,AWBCB" class="hidden" transform="translate(55 0)">
<rect class="hidden" height="22px" width="22px" transform="translate(0 0)"></rect>
<image xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAWCAYAAADEtGw7AAAAq0lEQVR42mNgoCWYMmXKfnx46tSp66dPn65AjsH/CeHJkyc3jBpMvsEgTcgYaNB9XAYDaQeyLEFKJTgNhorNp5XBILy/v79fgBYGg/B5og3HZjDI61BDC7DIvQdmIgNyDSaE3wMtDqCFwWAMdHkCTQwGYZzlCgUGg4LDAaeLQaUZOYYSFYF4cqkDFkPPk5SeiTR4P8WGYjF4PtVqGySDC6hajYEiCG9apTUAABIoGpLjU/7fAAAAAElFTkSuQmCC" height="22px" width="22px" transform="translate(0 0)"></image>
<text class="hidden" transform="translate(22 15)">0</text>
</g>
<g ontouchstart="runCommand(this)" onclick="runCommand(this)" data-commandid="com.siemens.splm.client.relations.internal.commands.expandtoparent" data-contextmenu="" data-tooltip="Show Parent" data-id="SR::N::Ase0LogicalElement..Fnd0LogicalBOMLine..5.6ZarDeTC8VoL5B.J$vlO1AI8VI9qC.Group:/Thid_wCYVM0YsoaNeFC,,AWBCB" class="aw-relations-nodeExpandToParentTargetSvg" transform="translate(135 0)">
<rect class="hidden" height="22px" width="22px" transform="translate(0 0)"></rect>
<image xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAWCAYAAADEtGw7AAAArklEQVR42mNgGJFg8uTJDVOnTk2gpoEOU6ZMuQ/E/0GGU2zg9OnTFYCG7QcZCMMUGdzf3y8ANKQf2UCKDQaFIdCA99gMJctgaDiex2UgyQaDwhHoyvWEDCTaYFA4ghTh8zbJBkPD8T4pBhI0GCgRQI6BxLrYAD19Ui2MkVx/n+oGI5cBxEYiyekYmn3nU91gtIyyn+oGE8raVCndkDIRdQ3Glu2pajBy+FO1BsEHAGDp1Mi22dsnAAAAAElFTkSuQmCC" height="22px" width="22px" transform="translate(0 0)"></image>
<text class="hidden" transform="translate(22 15)">1</text>
</g>
<g ontouchstart="runCommand(this)" onclick="runCommand(this)" data-commandid="com.siemens.splm.client.relations.internal.commands.children" data-contextmenu="" data-tooltip="" data-id="SR::N::Ase0LogicalElement..Fnd0LogicalBOMLine..5.6ZarDeTC8VoL5B.J$vlO1AI8VI9qC.Group:/Thid_wCYVM0YsoaNeFC,,AWBCB" class="hidden" transform="translate(172 0)">
<rect class="hidden" height="22px" width="22px" transform="translate(0 0)"></rect>
<image xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAWCAYAAADEtGw7AAAAmUlEQVR42mNgGNJg6tSp64HYgOoGT5ky5T8U9wOBAC0MBuH3QFxAC4Nh+P7kyZMdaGEwGIPCf/r06QpUNxiGga5vIDn8iTEYFv5AHyTQwmAY3k9U+JNhMAzPxxv+FBgMwuepbTDh9E5OEBCVQkiJNJLKFCIMBOXCAGpmkPdkZQwCBs8nOyvjMPg8xYUPmsGkZVdiAEXhSC8AAEMZxPHTyECZAAAAAElFTkSuQmCC" height="22px" width="22px" transform="translate(0 0)"></image>
<text class="hidden" transform="translate(22 15)">0</text>
</g>
</g>
</g>
</g>
<image preserveAspectRatio="none" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAACo0lEQVR42u2Yy2sTURTGa9EiRW2puxata8XnymIXWtGlSF0IuhGtD0SkOxddxE0LBUlCngQMcSlK6cJFsbT0P1DcCL7IphQVSxZSULGMv1NmxA6JzePcOxmYCx93JpnM/b5zz+umoyMa0YhG3SObzV7LZDJOiyiDRD6fP2BdgAJ5PxKM3jALELxWF4GrHEun06f9MCRgQ4SmlRMGif7XnbQELAUkwFEJ7CAFqOxCwALKYY4BPTeynEY3QbJdJCDUAtx+pxJUDEgRDXMWqlhNo2z3RfmNZA7uSwrWn7UtYJO/tipEJYAbIVBrwSaFLKlkGmltedk45B76UU1ALBbbzvV18Bss4wZ3mffK5w0IqVg54NQQ0MX1fd93nxByk+/7RYgYhftYjexWaTnzGBDg4S3kbot15bkqQsrWyFeLjzoEeNnlFfMDcKJQKHSnUqk9uVzuZCAHe/d0thETnmW3EvAPPoApyB8pFou72+KfigYFeHgHHrETRwMX0qSAvzuCe00j5DjzrjAK8PBRXAsRw8RITxgFeFgFGeJrpFQq7bSZncaUm7pv7EaS+RwG6jSVia6Ayyx0lYWeGOpOv4AUa5xXFcIL3/PiNfDdxU/Dh5wV5knmw6E5mVXBHAJOaQn4YYn0L/AG4hOk2oNSxcOyA2KgRWkImQ9BfId21nnhpryv4LMbBxrE18E8Fr/FPOg4zjYjaZMeaADrjLLQBTlWcv1Ygfy827kOSAtuo4B1ioVkexFxp4UM81IsDvl96q5Sz5BFWfxeEwf4pxC/lEwm91uxuFYrAekZKUzxeLzPSJU1KGAO4mekfTYWnMoC1t0KvQDOynNtRdwnYNxHXFLrc7F4W5L2BzF+fcOtmquQfqZW8m0MsTDEhyQ45ZhotABFow3HH7lTOrgIGVjwAAAAAElFTkSuQmCC" id="JTThumbnail" height="46px" width="46px" transform="translate(17 19)"></image>
</g>
<g transform="translate(214 164)"><rect stroke-miterlimit="10" stroke-linejoin="miter" stroke-linecap="butt" stroke-width="1" stroke-opacity="1" fill-opacity="1" class="aw-widgets-cellListItemSelected" y="0" x="0" height="22" width="22" stroke="rgb(0,0,0)" fill="rgb(255,255,255)"></rect>
</g>
<g transform="translate(236 141)"><text transform="translate(0 0)" dy="1em" fill-opacity="1" fill="rgb(0,0,0)" text-anchor="start" font-weight="600" font-style="normal" font-size="16px" font-family="Segoe UI">P</text></g>
</g>
<defs>
</defs>
</svg>
</div>
<div class="yfiles-overlaypanel">
<div class="yfiles-canvascontrol" tabindex="1" style="position: absolute; width: 300px; height: 125px; display: none;">
<div class="yfiles-svgpanel">
<div style="position:absolute;top:0;left:0;height:100%;width:100%;">
<svg style="position:absolute;top:0;left:0;height:100%;width:100%;pointer-events:none">
<g transform="translate(0 0)" style="pointer-events:visiblePainted">
<rect fill-opacity="1" stroke-miterlimit="10" stroke-linejoin="miter" stroke-linecap="butt" stroke-width="1" stroke-opacity="1" y="0" x="0" height="125" width="300" stroke="rgb(0,0,0)" fill="rgb(255,255,255)"></rect>
</g>
<defs>
</defs>
</svg>
</div>
</div>
<div style="cursor: default; display: none;" class="yfiles-scrollbar yfiles-scrollbar-vertical" tabindex="1">
<div class="yfiles-button yfiles-button-up">▲</div>
<div class="yfiles-scrollbar-range yfiles-scrollbar-range-vertical" tabindex="1">
<div class="yfiles-scrollbar-range-content"><div class="yfiles-scrollbar-slider">
<div class="yfiles-scrollbar-slider-content">
</div>
</div>
</div>
</div>
<div class="yfiles-button yfiles-button-down">▼</div>
</div>
<div style="cursor: default; display: none;" class="yfiles-scrollbar yfiles-scrollbar-horizontal" tabindex="1">
<div class="yfiles-button yfiles-button-left">◄</div>
<div class="yfiles-scrollbar-range yfiles-scrollbar-range-horizontal" tabindex="1">
<div class="yfiles-scrollbar-range-content"><div class="yfiles-scrollbar-slider">
<div class="yfiles-scrollbar-slider-content"></div>
</div>
</div>
</div>
<div class="yfiles-button yfiles-button-right">►</div>
</div>
</div>
</div>
</div>
<div style="cursor: default; width: 0px; bottom: 0px;" class="yfiles-scrollbar yfiles-scrollbar-vertical" tabindex="1">
<div class="yfiles-button yfiles-button-up">▲</div>
<div class="yfiles-scrollbar-range yfiles-scrollbar-range-vertical" tabindex="1">
<div class="yfiles-scrollbar-range-content">
<div style="height: 0px; margin-top: 0px;" class="yfiles-scrollbar-slider">
<div class="yfiles-scrollbar-slider-content"></div>
</div>
</div>
</div>
<div class="yfiles-button yfiles-button-down">▼</div>
</div>
<div style="cursor: default; height: 0px; right: 0px; display: none;" class="yfiles-scrollbar yfiles-scrollbar-horizontal" tabindex="1"><
div class="yfiles-button yfiles-button-left">◄</div><div class="yfiles-scrollbar-range yfiles-scrollbar-range-horizontal" tabindex="1">
<div class="yfiles-scrollbar-range-content">
<div style="width: 0px; margin-left: 0px;" class="yfiles-scrollbar-slider">
<div class="yfiles-scrollbar-slider-content"></div>
</div>
</div>
</div>
<div class="yfiles-button yfiles-button-right">►</div>
</div>
</div>
类型为ISingleLocator
的文件。
代码如下:
<rect stroke-miterlimit="10" stroke-linejoin="miter" stroke-linecap="butt" stroke-width="1" stroke-opacity="1" fill-opacity="1" class="aw-widgets-cellListItemSelected" y="0" x="0" height="22" width="22" stroke="rgb(0,0,0)" fill="rgb(255,255,255)"></rect> from given code.
我试过这个:
ISingleLocator m_nodeContainer1 = $( "div.aw-relations-innerContainer div div div svg g g rect.aw-widgets-cellListItemSelected " );
但是我无法获得该位置。请告诉我准确的CSS选择器来获取rect
标记。
答案 0 :(得分:0)
使用Selenium和Java查找WebElement
的方法有很多种。
这些可能是:
使用CSS选择器:
WebElement rect = find(By.cssSelector("aw-widgets-cellListItemSelected"));
使用XPATH选择器:
WebElement rect = find(By.xpath("//rect [contains(@class, 'aw-widgets-cellListItemSelected')]));
使用ID选择器:
WebElement rect = find(By.id("<your ID here>"));
但是忘记了ID,因为你没有给定矩形的@ID。
如果您有多个rect
这个类名,您还可以使用WebElements
代替WebElement
,这样您就可以获得包含所有结果的列表。