简体   繁体   English

找不到预期的}

[英]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. 但是,这是因为您在if (driver.Find...之后有3个语句,然后else期望在其前面有一个大括号。将条件语句括在大括号中将起作用。

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. 您还需要打开第二个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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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