带有follow-sibling的xpath

时间:2017-10-20 12:28:04

标签: selenium xpath automation

我想访问带有classname&table;表格悬停'的表格。这应该在class ==' box-title'其中包含未来20天的文本&OODR项目'。任何人都可以帮我解决这个问题吗?我尝试了跟随兄弟,但没有运气。提前致谢。



<?xml version="1.0" encoding="UTF-8"?>
<div id="topTenSellers" class="box box-solid box-primary frontpageWidget">
   <div class="box-header">
      <i class="fa fa-group" />
      <h3 class="box-title">OODR Items for next 20 Days</h3>
      <div class="box-tools pull-right">
         <button class="btn btn-primary btn-sm" data-widget="collapse">
            <i class="fa fa-minus" />
         </button>
      </div>
   </div>
   <!-- /.box-header -->
   <div class="box-body no-padding">
      <table class="table table-hover">
         <tbody>
            <tr>
               <th style="width: 10px">#</th>
               <th>Booking</th>
               <th>Item Start Date</th>
               <th>Site</th>
               <th>Supplier</th>
            </tr>
            <tr>
               <td>
                  <strong>1</strong>
               </td>
               <td>
                  <a href="" target="_blank">(642143)</a>
               </td>
               <td>21/10/2017 00:00:00</td>
               <td>Ski</td>
               <td>OODR - Out of Date Range</td>
            </tr>
         </tbody>
      </table>
   </div>
   <!-- /.box-body -->
</div>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:1)

您可以尝试enter image description here而不是import 'package:flutter/material.dart'; void main() { runApp(new MaterialApp(home: new FocusVisibilityDemo())); } class FocusVisibilityDemo extends StatefulWidget { @override _FocusVisibilityDemoState createState() => new _FocusVisibilityDemoState(); } class _FocusVisibilityDemoState extends State<FocusVisibilityDemo> { @override Widget build(BuildContext context) { return new Scaffold( appBar: new AppBar(title: new Text('Text Dialog Demo')), body: new Center( child: new RaisedButton( onPressed: _showDialog, child: new Text("Push Me"), ), ), ); } _showDialog() async { await showDialog<String>( context: context, child: new _SystemPadding(child: new AlertDialog( contentPadding: const EdgeInsets.all(16.0), content: new Row( children: <Widget>[ new Expanded( child: new TextField( autofocus: true, decoration: new InputDecoration( labelText: 'Full Name', hintText: 'eg. John Smith'), ), ) ], ), actions: <Widget>[ new FlatButton( child: const Text('CANCEL'), onPressed: () { Navigator.pop(context); }), new FlatButton( child: const Text('OPEN'), onPressed: () { Navigator.pop(context); }) ], ),), ); } } class _SystemPadding extends StatelessWidget { final Widget child; _SystemPadding({Key key, this.child}) : super(key: key); @override Widget build(BuildContext context) { var mediaQuery = MediaQuery.of(context); return new AnimatedContainer( padding: mediaQuery.viewInsets, duration: const Duration(milliseconds: 300), child: child); } } 提到following-sibling,而h3节点不是兄弟姐妹:

table

答案 1 :(得分:0)

如果该类名只有一个元素,则其中任何一个都可以。有一点需要注意,根据版本和浏览器,selenium可能会遇到类名中的空格。如果您发现是这种情况,则使用multiple contains来处理空格。

//table[contains(@class,'table table-hover')] 
//table[@class = 'table table-hover'] 

如果您在接下来的20天内需要将该元素作为该OODR项目的子元素

//h3[contains(text(),'OODR Items for the next 20 days')]/parent::div/following-sibling::div/table[@class ='table table-hover']

此路径使用您的锚点“OODR Items ..”,然后转到父级,然后转到兄弟,然后转到具有指定类名的项目。祝好运!