Xpath替换 / Selenium Java

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

Xpath replacement / Selenium Java

问题

我已成功执行了如下的点击操作:

chromeDriver.findElement(By.xpath("//div[@class='button button-primary cookie-accept-all']")).click();

经过调查,我发现不推荐使用 xpath,而是更好地使用 CSS 进行引用。

我如何能够用 @FindBy(className = ) 来实现与上面相同的操作?

英文:

I have managed to perform the click operation with the following :

chromeDriver.findElement(By.xpath("//div[@class='button button-primary cookie-accept-all']")).click();

I did the investigation and found out that it is not recommended to use xpath and much better to refer to css.

How can i possible do the same i did above with @FindBy(className = )

答案1

得分: 0

根据情况,您可以尝试类似这样的方法(未经测试):

chromeDriver.findElement(By.cssSelector(".button .button-primary .cookie-accept-all']")).click();

但请查阅相当有用的文档 https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors

英文:

In that case you can try something like this (not tested):

chromeDriver.findElement(By.cssSelector(".button .button-primary .cookie-accept-all']")).click();

But please check the documentation that is quite useful https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors

huangapple
  • 本文由 发表于 2020年10月12日 18:35:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/64316162.html
匿名

发表评论

匿名网友

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

确定