按Xpath查找包含文本的元素

时间:2015-07-28 10:47:55

标签: c# selenium xpath

如果我搜索单个字符串,这可以正常工作:

<ListBox ItemsSource="{Binding RoutenListe}" Grid.Row="1" HorizontalContentAlignment="Stretch" HorizontalAlignment="Stretch" BorderThickness="0" Margin="0" Padding="0" Background="#32557B" ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Auto">
    <local:WPM_ListBox.ItemTemplate>
        <DataTemplate>
            <local:WPM_ListBoxItem WPM_HeaderContent="{Binding Name}" 
                                   WPM_LabelContent1="{Binding Startort}"  WPM_LabelContent2="{Binding Zielort}" 
                                   Background="Transparent" WPM_HeaderContentMargin="6 2 0 0" WPM_HeaderContenFontSize="24" WPM_LabelContentMargin="3 -4 0 3" 
                                   WPM_LabelDescription1="Start:"  WPM_LabelDescription2="Ziel:" WPM_LabelDescriptionMargin="10 -4 0 3" />
        </DataTemplate>
    </local:WPM_ListBox.ItemTemplate>
</ListBox>

但是我可以在下面的示例中使用语句吗?

var resources = [<URL_1>, <URL_2>, <URL_3>, ...];
var resourcesText = resourceToText(resources);

function resourcesToText(resources) {
  var text = [];

  for (var i in resources) {
  request(resources[i], fetch);
  }

  function fetch(error, response, body) {
    if (!error) {
      text.push(body);
    } else {
      console.log('Sorry. I couldn\'t parse that resource. ' + error);
    }
  }

  return text;

};

2 个答案:

答案 0 :(得分:11)

or函数

的两次调用之间说contains
//a[contains(text(), 'About us') or contains(text(), 'about us')]

或使用translate函数使xpath不区分大小写

//a[contains(translate(text(), 'ABOUTS', 'abouts'), 'about us')]

答案 1 :(得分:1)

以下满足您的要求: -

// a [包含(。,&#39;关于我们&#39;)或包含(。,&#39;关于我们&#39;)]

请参阅: - https://sqa.stackexchange.com/questions/10342/how-to-find-element-using-contains-in-xpath了解更多详情。