I have a website with a link inside a div. The html source inspection from the webpage looks like this:
<div class="add-to-cart-wrapper">
<button data-tooltip="Only investments from the selected page will be sold." data-theme="dark" data-placement="top" data-tooltip-trigger="hover" data-id-list="48999040" class="btn btn-default tooltip-item trigger-sell-all">
Sell All
</button>
<a href="javascript:;" data-tooltip="Remove all investments from sale" data-placement="top" data-theme="dark" data-tooltip-trigger="hover" data-currency-iso-code="978" class="trigger-remove-all-sales">
<i class="fas fa-reply-all fa-flip-vertical"></i>
</a>
</div>
In the browser it looks like this:
What I am actually trying to archieve is to click on those two grey arrows beneath the "Sell All" button. Which matches the <a href="javascript:;" [...]>
Unfortunately the following C# code for Selenium (Chromedriver) returns that the element is currently not visible eventough I can click on it in the Browser manually:
var link = buttonWrapper.FindElement(By.ClassName("trigger-remove-all-sales"));
link.Click();
The Error Message looks like this:
OpenQA.Selenium.ElementNotVisibleException: 'element not visible
(Session info: chrome=68.0.3440.106) (Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 10.0.17134 x86_64)'
any suggestions on how to proceed?
EDIT: As per the suggestion, I added a 'wait.Until("element x is visible")' as per the below code. unfortunately I run into a timeout error:
new WebDriverWait(browser, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("div.add-to-cart-wrapper a.trigger-remove-all-sales[data-tooltip='Remove all investments from sale']"))).Click();
OpenQA.Selenium.WebDriverTimeoutException: 'Timed out after 20 seconds'
As per suggestion I tried to locate the Element with .FindElement()
What I noticed Is that the Property Displayed=false
I've added a Thread.Sleep(120000)
in between and looked up the code freshly to see what would change. This is the testing code:
var buttonWrapper = browser.FindElement(By.ClassName("add-to-cart-wrapper"));
var link = buttonWrapper.FindElement(By.ClassName("trigger-remove-all-sales"));
Thread.Sleep(120000);
buttonWrapper = browser.FindElement(By.ClassName("add-to-cart-wrapper"));
link = buttonWrapper.FindElement(By.ClassName("trigger-remove-all-sales"));
Even after a waiting time of 2 minutes the element is found but still shown as Displayed=false
In the Developer Console of google Chrome I observed the element and found the following property:
There is an event listener to a.trigger-remove-all-sales which might be used