Reputation: 47
I can't seem to find where to put } in this code snippet here. Simple problem but I couldn't get it to work.
foreach (string line in File.ReadLines(@"C:\\tumblrextract\\in7.txt"))
{
if (line.Contains("@"))
{
searchEmail.SendKeys(line);
submitButton.Click();
var result = driver.FindElement(By.ClassName("invite_someone_success")).Text;
var ifThere = driver.FindElements(By.XPath("//*[@id='invite_someone']/div"));
if (driver.FindElements(By.XPath("//*[@id='invite_someone']/div")).Count != 0)
// If invite_someone_failure exists open this url
driver.Url = "https://www.tumblr.com/lookup";
Thread.Sleep(3000);
driver.Url = "https://www.tumblr.com/following";
else
using (StreamWriter writer = File.AppendText("C:\\tumblrextract\\out7.txt"))
writer.WriteLine(result + ":" + line);
}
}
Upvotes: 1
Views: 56
Reputation: 35338
Proper formatting would help you find the error on your own. Nevertheless, it is because you have 3 statements after your if (driver.Find...
and then the else
expects a closing brace in front of it. Wrap the conditional statements in braces and it will work.
foreach (string line in File.ReadLines(@"C:\\tumblrextract\\in7.txt"))
{
if (line.Contains("@"))
{
searchEmail.SendKeys(line);
submitButton.Click();
var result = driver.FindElement(By.ClassName("invite_someone_success")).Text;
var ifThere = driver.FindElements(By.XPath("//*[@id='invite_someone']/div"));
if (driver.FindElements(By.XPath("//*[@id='invite_someone']/div")).Count != 0)
{
driver.Url = "https://www.tumblr.com/lookup";
Thread.Sleep(3000);
driver.Url = "https://www.tumblr.com/following";
}
// If invite_someone_failure exists open this url
else
{
using (StreamWriter writer = File.AppendText("C:\\tumblrextract\\out7.txt"))
{
writer.WriteLine(result + ":" + line);
}
}
}
}
Upvotes: 5
Reputation: 1102
Before else you need } after else you need {. You also need to open a close bracket for the second if.
foreach (string line in File.ReadLines(@"C:\\tumblrextract\\in7.txt"))
{
if (line.Contains("@"))
{
searchEmail.SendKeys(line);
submitButton.Click();
var result = driver.FindElement(By.ClassName("invite_someone_success")).Text;
var ifThere = driver.FindElements(By.XPath("//*[@id='invite_someone']/div"));
if (driver.FindElements(By.XPath("//*[@id='invite_someone']/div")).Count != 0)
{
// If invite_someone_failure exists open this url
driver.Url = "https://www.tumblr.com/lookup";
Thread.Sleep(3000);
driver.Url = "https://www.tumblr.com/following";
}//end of second if
else{
using (StreamWriter writer =File.AppendText("C:\\tumblrextract\\out7.txt"))
writer.WriteLine(result + ":" + line);
}//end of else
}//end of first if
}//end of foreach
Upvotes: 1