Reputation: 1
Hi i am having trouble with making this code work and i need help. the html code is
<span id="banner">Rolling in 10.00...</span>
this "Rolling in 10.00..." is an innerText and the 10.00 is a timer that means it will keep running until 0. I am interested in trying to run a code when the timer is at 20.00. example
<span id="banner">Rolling in 20.00...</span>
however i am having lots of trouble. this are some codes that work but have socket exception error (http://puu.sh/mubug/c33d8501bf.png)
public void waitroller2()
{
Console.WriteLine("start roller timer");
WebDriverWait wait = new WebDriverWait(PropertiesCollection.driver, TimeSpan.FromSeconds(1000));
Stopwatch watch = new Stopwatch();
IWebElement banner = wait.Until(ExpectedConditions.ElementIsVisible(By.Id("banner")));
watch.Start();
do
{
if (banner.Text.Equals("Rolling in 20.00..."))
{
Console.WriteLine("roller ended");
return;
}
} while (watch.Elapsed.Seconds < 1000);
throw new NoSuchElementException();
}
this method does not work at all
public void waitroller1()
{
Console.WriteLine("waitroller");
new WebDriverWait(PropertiesCollection.driver, TimeSpan.FromMinutes(1.5)).Until(ExpectedConditions.TextToBePresentInElement(rolling,"Rolling in 20.00..."));
Console.WriteLine("roller end");
}
i think the main problem is when i keep using this webdriverwait for long time it is not working have socket problem . pls i need help anyone can teach me how do it
Upvotes: 0
Views: 208
Reputation: 2703
That's what you need.
IWebElement banner = driver.FindElement(By.Id("banner")).Text;
bool status = false;
int tryTimes = 15;
do
{
if (banner.Text.Equals("Rolling in 20.00..."))
{
Console.WriteLine("roller ended");
status = true;
}
else
{
System.Threading.Thread.Sleep(1000);
banner = driver.FindElement(By.Id("banner")).Text;
tryTimes--;
}
} while (!status && tryTimes > 0);
Upvotes: 0
Reputation: 2703
Try this.
try
{
string timeToWait = new String(driver.FindElement(By.Id("banner")).Text.ToCharArray().Where(c => Char.IsDigit(c)).ToArray()).Substring(0,2);
int ttw = Convert.ToInt32(timeToWait);
System.Threading.Thread.Sleep(ttw * 1000);
}
catch(Exception ex)
{}
Upvotes: 0