如何在文本分为两行时编写单个xpath

时间:2015-05-06 06:48:27

标签: xpath robotframework

如何为此

编写单个xpath
// Setup NSURLConnection
NSURL *URL = [NSURL URLWithString:url];
NSURLRequest *request = [NSURLRequest requestWithURL:URL
                                     cachePolicy:NSURLRequestUseProtocolCachePolicy
                                 timeoutInterval:30.0];

NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection start];

// NSURLConnection Delegates
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
    if ([challenge previousFailureCount] == 0) {
        NSLog(@"received authentication challenge");
        NSURLCredential *newCredential = [NSURLCredential credentialWithUser:@"USER"
                                                                password:@"PASSWORD"
                                                             persistence:NSURLCredentialPersistenceForSession];
        NSLog(@"credential created");
        [[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge];
        NSLog(@"responded to authentication challenge");    
    }
    else {
        NSLog(@"previous authentication failure");
    }
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    ...
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    ...
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    ...
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    ...
}

我可以使用"包含"来写两行。方法

<div class="col-lg-4 col-md-4 col-sm-4 profilesky"> <div class="career_icon"> 
          <span> Boost </span> <br/>
          Your Profile </div>

但是我想在一行中为此写一个xpath。

2 个答案:

答案 0 :(得分:2)

您可以尝试这种方式:

.//*[@class='career_icon' and contains(., 'Boost') and contains(., 'Your Profile')]

在xpath上方检查是否存在类属性等于career_icon且元素正文中包含BoostYour Profile文本的元素。

请注意,text()仅检查直接子文本节点。要检查元素的全文内容,只需使用点(.)。

答案 1 :(得分:0)

您可以将几个规则组合在一起,因为它们引用相同的元素:

.//[contains(text(),'Boost')][contains(text(),'Your Profile')]