I have the following HTML code:
<spaui-accordion _ngcontent-ouh-c26="">
<spaui-accordion-tab _ngcontent-ouh-c26="" id="accordioAcordosPendentes" successtext="Carregando Acordos..." _nghost-ouh-c35="" class="ng-tns-c35-3 ng-star-inserted"><div _ngcontent-ouh-c35="" class="row"></div>
<div _ngcontent-ouh-c35="" class="accordion-tab" data-spaui-accordion-tab-header="Acordos (6)">
<!----><div _ngcontent-ouh-c35="" class="ng-tns-c35-3 ng-star-inserted">
<div _ngcontent-ouh-c35="" class="accordion-tab-heading">
<!---->
<!---->
<h4 _ngcontent-ouh-c35="" class="accordion-tab-title">
<!---->
<!---->
<!---->
<!---->
<!----><span _ngcontent-ouh-c35="" class="ng-tns-c35-3 label-margin ng-star-inserted" style="max-height: 50px;">
<!---->
<!----><div _ngcontent-ouh-c35="" class="animated-box ng-tns-c35-3 ng-star-inserted">
<p _ngcontent-ouh-c35="" class="ng-tns-c35-3" id="animatedText">Acordos (6)</p>
</div>
</span>
<!---->
<span _ngcontent-ouh-c35="" class="accordion-tab-button" style="cursor: pointer;">
<!----><em _ngcontent-ouh-c35="" class="ng-tns-c35-3 ng-star-inserted icon-seta-baixo"></em>
<!---->
</span>
<!---->
<!---->
<!---->
<!---->
<!---->
</h4>
</div>
</div>
<!---->
<!---->
<!---->
<!---->
</div>
</spaui-accordion-tab>
</spaui-accordion>
This code is shown after i’ve realyzed a few clicks steps on the page i’m trying to access with Selenium.
I’m having difficulties to wait for the accordion “accordioAcordosPendentes”. It takes a few seconds to load, however, i’ve tried all wait conditions available and couldn’t get it to wait until its available ; always throwing an exception that the element isn’t clickable.
However, if i’m debugging the code and just wait a few seconds…it will work. But even if i try Thread.Sleep on my code and leave it running, there are situations where it will just throw the exception
Here is what i’ve tried so far:
//var aguardaLinkAcordo = new WebDriverWait(driver, TimeSpan.FromSeconds(7)).Until(ExpectedConditions.ElementIsVisible((By.LinkText(tipoAcordo))));
// aguardaLinkAcordo.Click();
var linkAcordo = driver.FindElement(By.LinkText(tipoAcordo));
linkAcordo.Click();
new WebDriverWait(driver, TimeSpan.FromSeconds(15)).Until(ExpectedConditions.ElementToBeClickable((By.CssSelector("#accordioAcordosPendentes > div.accordion-tab > div > div > h4 > span.accordion-tab-button")))).Click();
// var disponivel = driver.FindElement(By.CssSelector("#accordioAcordosPendentes > div.accordion-tab > div > div > h4 > span.accordion-tab-button > em"));
// disponivel.Click();
//var aguardaAccordion = new WebDriverWait(driver, TimeSpan.FromSeconds(7)).Until(ExpectedConditions.ElementExists((By.CssSelector("#accordioAcordosPendentes > div.accordion-tab > div > div > h4 > span.accordion-tab-button > em"))));
// aguardaAccordion.Click(); //If the accordion is available for clicking (expanding), click on it to expand
//var availableX = Retry.Do(() => driver.FindElement(By.CssSelector("#accordioAcordosPendentes > div.accordion-tab > div > div > h4 > span.accordion-tab-button > em"))TimeSpan.FromSeconds(5),4);
// available.Click();
Of course, commented lines are what i’ve tried also but no success. I tried an method to ignore the exception and keep retrying, but no luck also:
public static IWebElement TryThreeTimes(IWebElement element)
{
var tries = 10;
while (true)
{
try
{
element.Click();
break; // success!
}
catch
{
if (--tries == 0)
throw;
Thread.Sleep(5000);
}
}
return element;
}
Any input is appreciated. Thanks a lot and sorry for the english.