-6

How to find the xpath of the button in a class. Please find the attachment of the same which i have uploaded:

image

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Pavan s
  • 1
  • 2

3 Answers3

0

Try this,

driver.findElement(By.xpath("//button[@data-target='@exampleModal1' and contains(text(),'Register')]"));
Ishita Shah
  • 3,955
  • 2
  • 27
  • 51
  • 1
    What you mean with not working ? What should we assume, In order to get it resolve you have to share your trial code and exception/error details. – Ishita Shah Sep 26 '18 at 07:45
0

As the element is a <button> tag simply identifying the element may not suffice to your usecase further you may need to invoke click() method on the element.

To invoke click() on the element as the element is within a Modal Dialog Box you need to induce WebDriverWait for the element to be clickable and you can use either of the following solutions:

  • cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.btn.btn-info.btn-lg-block.w3ls-btn1.px-4.text-uppercase[data-target$='exampleModal1']"))).click();
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.id("//button[@class='btn btn-info btn-lg-block w3ls-btn1 px-4 text-uppercase'][normalize-space()='REGISTER']"))).click();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Not working doesn't throws any light on whats wrong happening. Update the question with your code trials and error stack trace for further analysis – undetected Selenium Sep 26 '18 at 07:05
0

Try this using CSS Selector. Make sure to use proper waits

driver.findElement(By.cssSelector
     (.btn.btn-info.btn-lg-block.w3ls-btnl.px-4.text-uppercase)
 ).click();

Here type should not be used as it is not a node/tag name

driver.findElement(By.xpath("//div[@class='buttons']//button")).click();
//driver.findElement(By.xpath("//div[@class='buttons']/type")).click(); WRONG
  1. Make sure element should not be in frames else we have to first switchTo frame and then perform findElement

     driver.switchTo("frameName/ID") 
           .findElement(By.xpath("//div[@class='buttons']//button"))
           .click();
    
  2. Element should be loaded before click, you can use wait statement for this

Amit Jain
  • 4,389
  • 2
  • 18
  • 21