如何编写XPath以在标签中具有多个值(两行)。

huangapple go评论100阅读模式
英文:

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 )']

但不起作用。

如何编写XPath以在标签中具有多个值(两行)。

英文:

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.

如何编写XPath以在标签中具有多个值(两行)。

<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')]")))

huangapple
  • 本文由 发表于 2020年8月5日 16:37:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/63261370.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定