0

The following inspect code i have is to click the button I can confirm my order

<button type="submit" class="button btn btn-default button-medium">
                <span>I confirm my order<i class="icon-chevron-right right"></i></span>
</button>
<span>I confirm my order<i class="icon-chevron-right right"></i></span>

The one I've tried:

driver.findElement(By.xpath("//button[contains(text(),'I confirm my order')]\"")).click();

The error is coming out using Eclipse as IDE for Selenium Testing stated below:

org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression //button[contains(text(),'I confirm my order')]" because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//button[contains(text(),'I confirm my order')]"' is not a valid XPath expression.
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

2 Answers2

0

Try this:

driver.find_element_by_xpath('//button[@type="submit"]/span[1]').click()
TheLegend42
  • 71
  • 1
  • 5
0

The text I confirm my order is within the child <span> of the <button> element. So, to click() on the element you can use either of the following Locator Strategies:

  • cssSelector:

    driver.findElement(By.cssSelector("button.button.btn.btn-default.button-medium > span i.icon-chevron-right.right")).click();
    
  • xpath:

    driver.findElement(By.xpath("//button[@class='button btn btn-default button-medium'][./span[contains(., 'I confirm my order')]]")).click();
    

However, as the element is a JavaScript enabled element so to click() on the element you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.button.btn.btn-default.button-medium > span i.icon-chevron-right.right"))).click();
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@class='button btn btn-default button-medium'][./span[contains(., 'I confirm my order')]]"))).click();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352