英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论