简体   繁体   中英

Can't find expected }

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);
                    }
                }

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);
            }
        }
    }
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM