简体   繁体   English

如何在 label 中编写具有多个值(两行)的 xpath

[英]How to write xpath which have multiple values (two lines) in label

I have tried this,我试过这个,

//label[text()='Legal Business Nam (you can add a DBA after your account is open )'] //label[text()='Legal Business Nam(开户后可以添加DBA)']

//label[text()='Legal Business Name' and '(you can add a DBA after your account is open )'] //label[text()='Legal Business Name' and '(开户后可以添加DBA)']

but does not work.但不起作用。

<div class="form-group col-md-12"><label>Legal Business Name (you can add a DBA after your account is open )</label><input type="text" class="form-control required" placeholder="Enter legal business name" name="company_name" maxlength="250" value=""><label id="company_name-error" class="help-block text-danger validation-error" for="company_name"></label></div>

You can try to use .您可以尝试使用. instead of text() .而不是text()

//label[contains(., 'Legal Business Name (you can add a DBA after your account is open )')]

Or just join 2 [contains(text(), '')] statements like this:或者像这样加入 2 个[contains(text(), '')]语句:

//label[contains(text(), 'Legal Business Name ')][contains(text(), '(you can add a DBA after your account is open )')]

Seems you were close enough.看来你已经够近了。 Instead of text() you need to use contains() as follows:您需要使用contains()而不是text() ) ,如下所示:

//label[contains(., 'you can add a DBA after your account is open')]

Ideally, you have to induce WebDriverWait for the visibilityOfElementLocated() and you can use the following based Locator Strategy :理想情况下,您必须为visibilityOfElementLocated()引入WebDriverWait ,并且可以使用以下基于定位器策略

new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//label[contains(., 'you can add a DBA after your account is open')]")))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM