-1

This is an HTML code I need help to write XPath for this. I have tried to write x-path but it does not hit the system correctly?

<div class="col-1-12" data-reactid="17">
    <button class="vh79eN" type="submit" data-reactid="18">
    <svg width="20px" height="20px" viewBox="0 0 17 18" class="" xmlns="http://www.w3.org/2000/svg" data-reactid="19">
    <g fill="#2874F1" fill-rule="evenodd" data-reactid="20">
    <path class="_2BhAHa" d="m11.618 9.897l4.225 4.212c.092.092.101.232.02.313l-1.465 1.46c-.081.081-.221.072-.314-.02l-4.216-4.203" data-reactid="21">
    </path>
    <path class="_2BhAHa" d="m6.486 10.901c-2.42 0-4.381-1.956-4.381-4.368 0-2.413 1.961-4.369 4.381-4.369 2.42 0 4.381 1.956 4.381 4.369 0 2.413-1.961 4.368-4.381 4.368m0-10.835c-3.582 0-6.486 2.895-6.486 6.467 0 3.572 2.904 6.467 6.486 6.467 3.582 0 6.486-2.895 6.486-6.467 0-3.572-2.904-6.467-6.486-6.467" data-reactid="22">
    </path>
    </g>
    </svg>
    </button>
    </div>

Please, help me to write correct XPath I have tried with:

driver.findElement(By.xpath("//div[@class='col-1-12']//button[@class='vh79eN']")).click();

but it does not work.

Ratmir Asanov
  • 6,237
  • 5
  • 26
  • 40

2 Answers2

0

The following XPath can be tried :

//div/button[@class='vh79eN'][@type='submit']

So the function will be:

driver.findElement(By.xpath("//div/button[@class='vh79eN'][@type='submit']")).click().
Jules Dupont
  • 7,259
  • 7
  • 39
  • 39
0

If data-reactid is consistent every time page is visited, you could try: //button[@data-reactid='18']

Note: If the element is inside of an iframe, you will have to switch to the iframe, then try to click.

bjones01001101
  • 1,071
  • 1
  • 12
  • 21