英文:
How to write xpath which have multiple values (two lines) in label
问题
我已经尝试过这个,
//label[text()='Legal Business Nam (you can add a DBA after your
account is open )']
//label[text()='Legal Business Name' and '(you can add a DBA after
your account is open )']
但不起作用。
英文:
I have tried this,
> //label[text()='Legal Business Nam (you can add a DBA after your
> account is open )']
>
>
> //label[text()='Legal Business Name' and '(you can add a DBA after
> your account is open )']
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>
答案1
得分: 2
你可以尝试使用.
而不是text()
。
//label[contains(., 'Legal Business Name (you can add a DBA after your account is open )')]
或者只需将两个[contains(text(), '')]
语句连接在一起,像这样:
//label[contains(text(), 'Legal Business Name ')][contains(text(), '(you can add a DBA after your account is open )')]
英文:
You can try to use .
instead of 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:
//label[contains(text(), 'Legal Business Name ')][contains(text(), '(you can add a DBA after your account is open )')]
答案2
得分: 0
看起来你已经足够接近了。你需要使用contains()
而不是text()
,如下所示:
//label[contains(., 'you can add a DBA after your account is open')]
理想情况下,你应该使用WebDriverWait等待visibilityOfElementLocated()
,并可以使用以下基于xpath的定位策略:
new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//label[contains(., '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:
//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 [tag:xpath] based Locator Strategy:
new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//label[contains(., 'you can add a DBA after your account is open')]")))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论