How to enter xPath expression (Java)

I got the following problem:

I used google chrome function to get xPath expression for button, but I don't know how to use this expression in my java code.

I got the following expression from Google Chrome: // * [@id = "watch8-sentiment-actions"] / span / span [3] / button

I want to use this xPath expression in the following code:

WebDriver driver = new HtmlUnitDriver();

 driver.get(url);

 driver.findElement(By.xpath(" "));

      

+3


source to share


2 answers


WebElement button = driver.findElement(By.xpath("//*[@id='watch8-sentiment-actions']/span/span[3]/button"));

      

Note the single quotes inside the xpath expression!

no you can also click a button, for example:



button.click();

      

After doing a little research, I now know that this button is a downvote button on youtube, so your best bet is to try this code with your own videos.

0


source


This is much better:



driver.findElement(By.xpath("//*[@id='watch8-sentiment-actions']/span/span[3]/button")).click();

      

0


source







All Articles