I am having a bit of trouble locating a particular button in one of the ecommerce applications I am writing automation for. Here is a snippet of the mark-up:
<button class="btn btn-primary btn-sm" style="margin-right:0" data-href="/LABaaS/LABaaSShoppingCart" data-toggle="modal" data-target="#confirm-delete" id="btnAddtoCart">
<span class="glyphicon glyphicon-shopping-cart"></span> Add to Cart
</button>
As you can see, it has an id
right there in the mark-up so, I tried:
[FindsBy(How = How.Id, Using = "btnAddtoCart"), CacheLookup]
public IWebElement btnLaBaaSStorageDetailsAddToCart { get; set; }
That didn't work so, I tried the CssSelector
:
[FindsBy(How = How.CssSelector, Using = "button#btnAddtoCart.btn.btn-primary.btn-sm"), CacheLookup]
public IWebElement btnLaBaaSStorageDetailsAddToCart { get; set; }
That also failed so, I gave XPath
its requisite turn:
[FindsBy(How = How.XPath, Using = "//*[@id=\"btnAddtoCart\"]"), CacheLookup]
public IWebElement btnLaBaaSStorageDetailsAddToCart { get; set; }
If you guessed that this approach failed too, you win (something?)! So, as a last-ditch effort, I bravely attempted to use the ClassName
:
[FindsBy(How = How.ClassName, Using = "btn btn-primary btn-sm"), CacheLookup]
public IWebElement btnLaBaaSStorageDetailsAddToCart { get; set; }
I am well and truly stumped now. I am guessing there is a way to find it via some custom XPath
but, my knowledge is limited on that subject. Does anyone have any suggestions?