簡體   English   中英

找不到預期的}

[英]Can't find expected }

我似乎找不到在此代碼段中的}位置。 簡單的問題,但我無法正常工作。

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

正確的格式化將幫助您自行查找錯誤。 但是,這是因為您在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);
            }
        }
    }
}

之前需要},否則需要{。 您還需要打開第二個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