[英]How to locate the button using Selenium
I tried to find this code 我试图找到此代码
<div class="ads-form-bottom__submit">
<button type="submit" class="ads-form-bottom__publish button button-orange" title="Enviar anúncio"> Enviar anúncio</button>
</div>
using the XPath 使用XPath
//div[class='ads-form-bottom__submit'][2]/button/following-sibling::div[1]
and 和
//div[@class='ads-form-bottom__submit']/following-sibling::button
but it doesn't work. 但这不起作用。
There doesn't appear to be a reason to use following-sibling::
. 似乎没有理由使用
following-sibling::
。
Try: 尝试:
//div[contains(@class,'ads-form-bottom__submit')]/button[contains(@class,'ads-form-bottom__publish')]
迁移到$(By.id(“”)可以缓解很多Xpath问题
To locate the button with text as Enviar anúncio you can use either of the following Locator Strategies : 要将带有文本的按钮定位为Enviaranúncio ,可以使用以下定位策略之一 :
Using CSS_SELECTOR
: 使用
CSS_SELECTOR
:
div.ads-form-bottom__submit>button.ads-form-bottom__publish.button.button-orange[title='Enviar anúncio']
Using XPATH
: 使用
XPATH
:
//div[@class='ads-form-bottom__submit']/button[@class='ads-form-bottom__publish button button-orange' and @title='Enviar anúncio']
your both xpaths are incorrect. 您的两个xpath都不正确。 first one is missing '@' and in second 'button' is not sibling, rather its a child.
第一个是“ @”,第二个是“ button”,不是兄弟,而是子级。
use this 用这个
//button[contains(text(), 'Enviar anúncio')]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.