I have this sample code:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
public class App {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new HtmlUnitDriver();
driver.get("http://www.hepsiburada.com");
WebElement element = driver.findElement(By.xpath("//*[@id=\"tabBestSelling\"]/div/div/div/div/div/ul/li[1]/div/a"));
element.click();
System.out.println("Page title is: " + driver.getTitle());
element = driver.findElement(By.xpath("//*[@id=\"addToCart\"]"));
System.out.println(element);
driver.quit();
}
}
When I run this code, element will be printed as:
<button type="button" class="btn m button" id="addToCart" data-catalogname="Telefon" data-isvariants="true" disabled="disabled" data-bind="click: $parent.addCurrentItemToCart.bind($parent), attr:{'data-price':webtrekkCost, 'data-sku':sku, 'data-loginstatus':webtrekkLoginStatus}">
I do not understand why this button is disabled? When I navigate to the same page with my browser, the button is not disabled.
An example page: http://www.hepsiburada.com/htc-one-m8-p-TELCEPHTCM8-G
Edit
I also tried:
WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id=\"addToCart\"]")));
which did not work... I get a timeout..