有如下表格
我想选择'nav test-step-actions'
类的元素。
有多个数据,但由于碰巧发生了变化,因此无法使用其他ID和内容
所以我试图单独制作tr,但我找不到解决方案。 我试过的代码:
self.gearbu= self.driver.find_element_by_xpath("//form[@id='project-config-versions-add']/tr[0]/td[class='nav test-step-actions']")
self.gearbu= self.driver.find_element_by_xpath("//tbody[@id='zephyr-restfultable-tbody']/tr[0]/td[6]")
<form id="project-config-versions-add" class="aui" action="#">
<table id="project-config-steps-table" class="aui jira-restfultable jira-restfultable-allowhover">
<thead>
<tr>
<th class="jira-restfultable-order"><!-- order --></th>
<th></th>
<th>Test Step</th>
<th>Test Data</th>
<th>Expected Result</th>
<th><!-- Operations --></th>
<!--<th style="width:100px;"> throbber </th>-->
</tr>
</thead>
<tbody id="zephyr-restfultable-tbody" class="ui-sortable"><tr classname="project-config-version" id="step-126-row" data-id="126" class="jira-restfultable-row jira-restfultable-readonly"><td class="jira-restfultable-order"><span class="jira-restfultable-draghandle"></span></td><td class="project-config-version-name zteststep-order"><span data-field-name="orderId" class="zfj-nowrap">1</span></td><td class="project-config-version-description zteststep-step"><span class="jira-restfultable-editable zfj-editable-field" data-field-name="step"><span class="icon icon-edit-sml zfj-overlay-icon"></span><p>a</p></span></td><td class="project-config-version-description zteststep-data "><span class="jira-restfultable-editable zfj-editable-field" data-field-name="data"><span class="icon icon-edit-sml zfj-overlay-icon"></span><p>b</p></span></td><td class="project-config-version-description zteststep-result "><span class="jira-restfultable-editable zfj-editable-field" data-field-name="result"><span class="icon icon-edit-sml zfj-overlay-icon"></span><p>c</p></span></td><!--<td class="project-config-operations" style="width:50px;">c</td>--><td class="nav test-step-actions"><a href="teststep-dd-126" aria-owns="teststep-dd-126" aria-haspopup="true" class="aui-steps-dropdown aui-dropdown2-trigger aui-style-default aui-dd-link icon-tools-small" style="visibility: hidden;" data-clicked="0" aria-controls="teststep-dd-126"><span class="aui-icon aui-icon-small"></span></a><!-- .aui-dropdown2 --><div id="teststep-dd-126" class="aui-dropdown2 aui-style-default" data-dropdown2-alignment="left" aria-hidden="true" style="left: 1171px; top: 698px; display: none;"><ul class="aui-list-truncate"><li><a href="#" id="step-126-action-clone" class="test-step-action-clone" style="visibility: visible;" data-clicked="0">Clone</a></li><li><a id="step-126-operations-trigger" class="project-config-operations-trigger" href="#" style="visibility: visible;" data-clicked="0">Delete</a></li></ul></div></td><!--<td class="project-config-throbber"></td>--></tr><tr classname="project-config-version" id="step-127-row" data-id="127" class="jira-restfultable-row jira-restfultable-readonly"><td class="jira-restfultable-order"><span class="jira-restfultable-draghandle"></span></td><td class="project-config-version-name zteststep-order"><span data-field-name="orderId" class="zfj-nowrap">2</span></td><td class="project-config-version-description zteststep-step"><span class="jira-restfultable-editable zfj-editable-field" data-field-name="step"><span class="icon icon-edit-sml zfj-overlay-icon"></span><p>d</p></span></td><td class="project-config-version-description zteststep-data "><span class="jira-restfultable-editable zfj-editable-field" data-field-name="data"><span class="icon icon-edit-sml zfj-overlay-icon"></span><p>a</p></span></td><td class="project-config-version-description zteststep-result "><span class="jira-restfultable-editable zfj-editable-field" data-field-name="result"><span class="icon icon-edit-sml zfj-overlay-icon"></span><p>d</p></span></td><!--<td class="project-config-operations" style="width:50px;">c</td>--><td class="nav test-step-actions"><a href="teststep-dd-127" aria-owns="teststep-dd-127" aria-haspopup="true" class="aui-steps-dropdown aui-dropdown2-trigger aui-style-default aui-dd-link icon-tools-small" style="visibility: hidden;" aria-controls="teststep-dd-127" data-clicked="0"><span class="aui-icon aui-icon-small"></span></a><!-- .aui-dropdown2 --><div id="teststep-dd-127" class="aui-dropdown2 aui-style-default" data-dropdown2-alignment="left" aria-hidden="true" style="left: 695px; top: 788px; display: none;"><ul class="aui-list-truncate"><li><a href="#" id="step-127-action-clone" class="test-step-action-clone" style="visibility: visible;" data-clicked="0">Clone</a></li><li><a id="step-127-operations-trigger" class="project-config-operations-trigger" href="#" style="visibility: visible;" data-clicked="0">Delete</a></li></ul></div></td><!--<td class="project-config-throbber"></td>--></tr><tr classname="project-config-version" id="step-128-row" data-id="128" class="jira-restfultable-row jira-restfultable-readonly"><td class="jira-restfultable-order"><span class="jira-restfultable-draghandle"></span></td><td class="project-config-version-name zteststep-order"><span data-field-name="orderId" class="zfj-nowrap">3</span></td><td class="project-config-version-description zteststep-step"><span class="jira-restfultable-editable zfj-editable-field" data-field-name="step"><span class="icon icon-edit-sml zfj-overlay-icon"></span><p>h</p></span></td><td class="project-config-version-description zteststep-data "><span class="jira-restfultable-editable zfj-editable-field" data-field-name="data"><span class="icon icon-edit-sml zfj-overlay-icon"></span><p>g</p></span></td><td class="project-config-version-description zteststep-result "><span class="jira-restfultable-editable zfj-editable-field" data-field-name="result"><span class="icon icon-edit-sml zfj-overlay-icon"></span><p>d</p></span></td><!--<td class="project-config-operations" style="width:50px;">c</td>--><td class="nav test-step-actions"><a href="teststep-dd-128" aria-owns="teststep-dd-128" aria-haspopup="true" class="aui-steps-dropdown aui-dropdown2-trigger aui-style-default aui-dd-link icon-tools-small" style="visibility: hidden;" aria-controls="teststep-dd-128" data-clicked="0"><span class="aui-icon aui-icon-small"></span></a><!-- .aui-dropdown2 --><div id="teststep-dd-128" class="aui-dropdown2 aui-style-default" data-dropdown2-alignment="left" aria-hidden="true" style="left: 695px; top: 838px; display: none;"><ul class="aui-list-truncate"><li><a href="#" id="step-128-action-clone" class="test-step-action-clone" style="visibility: visible;">Clone</a></li><li><a id="step-128-operations-trigger" class="project-config-operations-trigger" href="#" style="visibility: visible;">Delete</a></li></ul></div></td><!--<td class="project-config-throbber"></td>--></tr><tr classname="project-config-version" id="step-129-row" data-id="129" class="jira-restfultable-row jira-restfultable-readonly"><td class="jira-restfultable-order"><span class="jira-restfultable-draghandle"></span></td><td class="project-config-version-name zteststep-order"><span data-field-name="orderId" class="zfj-nowrap">4</span></td><td class="project-config-version-description zteststep-step"><span class="jira-restfultable-editable zfj-editable-field" data-field-name="step"><span class="icon icon-edit-sml zfj-overlay-icon"></span><p>a</p></span></td><td class="project-config-version-description zteststep-data "><span class="jira-restfultable-editable zfj-editable-field" data-field-name="data"><span class="icon icon-edit-sml zfj-overlay-icon"></span><p>b</p></span></td><td class="project-config-version-description zteststep-result "><span class="jira-restfultable-editable zfj-editable-field" data-field-name="result"><span class="icon icon-edit-sml zfj-overlay-icon"></span><p>c</p></span></td><!--<td class="project-config-operations" style="width:50px;">c</td>--><td class="nav test-step-actions"><a href="teststep-dd-129" aria-owns="teststep-dd-129" aria-haspopup="true" class="aui-steps-dropdown aui-dropdown2-trigger aui-style-default aui-dd-link icon-tools-small" style="visibility: hidden;"><span class="aui-icon aui-icon-small"></span></a><div id="teststep-dd-129" class="aui-dropdown2 aui-style-default"><ul class="aui-list-truncate"><li><a href="#" id="step-129-action-clone" class="test-step-action-clone" style="visibility: visible;">Clone</a></li><li><a id="step-129-operations-trigger" class="project-config-operations-trigger" href="#" style="visibility: visible;">Delete</a></li></ul></div><!-- .aui-dropdown2 --></td><!--<td class="project-config-throbber"></td>--></tr><tr classname="project-config-version" id="step-130-row" data-id="130" class="jira-restfultable-row jira-restfultable-readonly"><td class="jira-restfultable-order"><span class="jira-restfultable-draghandle"></span></td><td class="project-config-version-name zteststep-order"><span data-field-name="orderId" class="zfj-nowrap">5</span></td><td class="project-config-version-description zteststep-step"><span class="jira-restfultable-editable zfj-editable-field" data-field-name="step"><span class="icon icon-edit-sml zfj-overlay-icon"></span><p>a</p></span></td><td class="project-config-version-description zteststep-data "><span class="jira-restfultable-editable zfj-editable-field" data-field-name="data"><span class="icon icon-edit-sml zfj-overlay-icon"></span><p>b</p></span></td><td class="project-config-version-description zteststep-result "><span class="jira-restfultable-editable zfj-editable-field" data-field-name="result"><span class="icon icon-edit-sml zfj-overlay-icon"></span><p>c</p></span></td><!--<td class="project-config-operations" style="width:50px;">c</td>--><td class="nav test-step-actions"><a href="teststep-dd-130" aria-owns="teststep-dd-130" aria-haspopup="true" class="aui-steps-dropdown aui-dropdown2-trigger aui-style-default aui-dd-link icon-tools-small" style="visibility: hidden;"><span class="aui-icon aui-icon-small"></span></a><div id="teststep-dd-130" class="aui-dropdown2 aui-style-default"><ul class="aui-list-truncate"><li><a href="#" id="step-130-action-clone" class="test-step-action-clone" style="visibility: visible;">Clone</a></li><li><a id="step-130-operations-trigger" class="project-config-operations-trigger" href="#" style="visibility: visible;">Delete</a></li></ul></div><!-- .aui-dropdown2 --></td><!--<td class="project-config-throbber"></td>--></tr></tbody><tbody class="jira-restfultable-create"><tr class="jira-restfultable-row jira-restfultable-editrow jira-restfultable-focused"><td class="jira-restfultable-order"><span class="jira-restfultable-draghandle"></span></td><td></td><td class="teststep-editable teststep-editable-step"><textarea name="step" rows="4" class="ztextarea noresize ztextarea-step"></textarea> <div class="wiki-preview-content"></div><div class="wiki-field-tools"><a class="zephyr-wiki-preview_link fullscreen" tabindex="-1" href="#" id="zephyr-wiki-preview_link" title="preview"><span class="aui-icon wiki-renderer-icon"></span></a><a class="help-link" id="viewHelp" tabindex="-1" href="/secure/WikiRendererHelpAction.jspa?section=all" title="Get local help about wiki markup help" data-helplink="local"><span class="aui-icon aui-icon-small aui-iconfont-help"></span></a></div></td><td class="teststep-editable teststep-editable-data"><textarea name="data" rows="4" class="ztextarea noresize ztextarea-data"></textarea> <div class="wiki-preview-content"></div><div class="wiki-field-tools"><a class="zephyr-wiki-preview_link fullscreen" tabindex="-1" href="#" id="zephyr-wiki-preview_link" title="preview"><span class="aui-icon wiki-renderer-icon"></span></a><a class="help-link" id="viewHelp" tabindex="-1" href="/secure/WikiRendererHelpAction.jspa?section=all" title="Get local help about wiki markup help" data-helplink="local"><span class="aui-icon aui-icon-small aui-iconfont-help"></span></a></div></td><td class="teststep-editable teststep-editable-result"><textarea name="result" rows="4" class="ztextarea noresize ztextarea-result"></textarea> <div class="wiki-preview-content"></div><div class="wiki-field-tools"><a class="zephyr-wiki-preview_link fullscreen" tabindex="-1" href="#" id="zephyr-wiki-preview_link" title="preview"><span class="aui-icon wiki-renderer-icon"></span></a><a class="help-link" id="viewHelp" tabindex="-1" href="/secure/WikiRendererHelpAction.jspa?section=all" title="Get local help about wiki markup help" data-helplink="local"><span class="aui-icon aui-icon-small aui-iconfont-help"></span></a></div></td><!-- Original code --><!--<td class="jira-restfultable-icon project-config-release-status"><span class="project-config-icon project-config-icon-version"></span></td><td class="project-config-version-name"><input name="name" type="text" class="text" value="" /><input name="project" type="hidden" value="undefined"></td><td class="project-config-version-description"><input name="description" type="text" class="text" value="" /></td><td class="project-config-version-release-date"><div class="project-config-date-field"><input id="project-config-version-release-date-field" name="userReleaseDate" type="text" class="text short-field" value="" /><a href="#" id="project-config-versions-release-date-trigger" title="Select a date"><span class="aui-icon icon-date">Select a date</span></a></div></td>--><td class="jira-restfultable-operations"><div class="restfultable-operations-wrapper"><input class="aui-button" type="submit" value="Add"></div></td><td class="jira-restfultable-throbber"></td></tr></tbody></table>
</form>
如何在selenium中找到xpath元素?
答案 0 :(得分:0)
您的第二个xpath是错误的,因为在xpath中,计数从1开始(不是0)。正确的版本是:
//tbody[@id='zephyr-restfultable-tbody']/tr[1]/td[6]
你的第一个xpath错误是因为:a)计算错误; b)a&lt; tr&gt;不是形式的直接孩子(单斜线而不是双斜线); c)xpath中的属性名称必须以'@'开头。更正确的版本是:
//form[@id='project-config-versions-add']//tbody[@id='zephyr-restfultable-tbody']/tr[1]/td[@class='nav test-step-actions']
或者chorter one:
//form[@id='project-config-versions-add']//tr[1]/td[@class='nav test-step-actions']