/// <summary> /// 방에 들어와 있는 상태에서 로그인 시도, /// </summary> /// <param name="Drv"></param> private static void login_afreeca(IWebDriver Drv, string ID, string PW) { try { //IWebElement login_button = Drv.FindElement(By.LinkText("로그인")); IWebElement login_button = WebDriverExtensions.FindElement(Drv, By.XPath("//*[@id=\"topbox\"]/div/ul/li[1]/a/span"), 5); Drv.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 5)); if (login_button != null) { click_element(Drv, login_button); Drv.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 5)); Thread.Sleep(500); click_element(Drv, login_button); WebDriverWait wait2 = new WebDriverWait(Drv, new TimeSpan(0, 0, 5)); wait2.Until(ExpectedConditions.PresenceOfAllElementsLocatedBy(By.Id("szUid"))); IWebElement tbox_id = Drv.FindElement(By.Id("szUid")); tbox_id.SendKeys(ID); IWebElement tbox_pw = Drv.FindElement(By.Id("szPassword")); tbox_pw.SendKeys(PW); IWebElement btn_login = Drv.FindElement(By.ClassName("btn_login")); btn_login.Click(); } } catch (NoSuchElementException e) { Console.WriteLine("로그인 실패 : {0}", e.ToString()); } catch { } }
private static bool login_check(IWebDriver Drv) //로그인 체크 { IWebElement WD = WebDriverExtensions.FindElement(Drv, By.Id("topmenu_name"), 5); if (WD != null) { string display = WD.Text; if (display.Length > 3) //디스플레이 되 있으면 로그인 된 것으로 간주. { return(true); } else { return(false); } } else { return(false); //5초간 확인 불가라면 로그인 실패로 간주. } }
private static void Thread__Enter_Afreeca_Room(object connection_) { i_connect C = (i_connect)connection_; if (Enter_Afreeca_Room_to_Mobile() && (!tester)) //테스터면 절대 안됨. { C.URL = C.URL.Replace("play.afreecatv.com", "m.afreecatv.com/#/player"); } try { int timeout_ = timeout; bool connected = false; if (C.Proxy == "") { Console.WriteLine("ERROR: Can't connect. \r\n Not set proxy Server."); return; } var chromeOptions = new ChromeOptions(); if (!none_proxy) { string server = Convert.ToString(C.Proxy); var proxy = new Proxy(); proxy.HttpProxy = server; chromeOptions.Proxy = proxy; } //시크릿 모드로.. 섹션 분리 chromeOptions.AddArgument("--incognito"); chromeOptions.AddArgument("--silent"); IWebDriver Driver = new ChromeDriver(@".\", chromeOptions); lock (Ldriver) { Ldriver.Insert(C.No, Driver); } Driver.Navigate().GoToUrl(C.URL); if (C.URL.Contains("m.afreecatv.com")) //모바일 ========================================================= { while (true) { Console.Write("X{0}.", timeout_); try { IWebElement btn_normal_q = WebDriverExtensions.FindElement(Driver, By.ClassName("low"), 5); IWebElement startBtnGroup = WebDriverExtensions.FindElement(Driver, By.Id("startBtnGroup"), 5); //startBtnGroup if (btn_normal_q != null) { string disp = startBtnGroup.GetCssValue("display"); if (disp.Contains("none")) //없으면 접속된거 { ReadOnlyCollection <IWebElement> in_broadcasting = WebDriverExtensions.FindElements(Driver, By.TagName("dd"), 5); bool is_inbroad = false; foreach (IWebElement ele in in_broadcasting) { if (is_방송에_입장하셨습니다(ele.Text)) { is_inbroad = true; break; } } if (is_inbroad) { connected = true; TefreecaUnit_interface.Add_Command( //상태를 업데이트 하도록 한다. Command_Client.Updated_Connection, new i_Updated_Connection(C.No, i_Updated_Connection_Type.State_Connect, State_Connect.Connected)); process_do_Low(); //모든 크롬 창 최소화. break; } } else //있으면 접속안된거.. { Thread.Sleep(2000); WebDriverExtensions.element_click(Driver, btn_normal_q); } } } catch { } if (timeout_-- <= 0) //0이하면 탈출.. { break; } Thread.Sleep(1000); } if (!connected) { if (!none_proxy && timeout > 100) { TefreecaUnit_interface.Add_Command(Command_Client.Change_Proxy, null); } else { if (timeout <= 100) { timeout += 20; } TefreecaUnit_interface.Add_Command( //상태를 업데이트 하도록 한다. Command_Client.Updated_Connection, new i_Updated_Connection(C.No, i_Updated_Connection_Type.State_Connect, State_Connect.Failure)); } } } //============================================================================================ else //pc { while (true) { try { Console.Write("X{0}.", timeout_); IWebElement nn = Driver.FindElement(By.XPath("//*[@id=\"broad_info\"]/dl/dt")); if (!is_방송을_불러오고_있습니다(nn.Text.ToString())) //연결되면 { connected = true; TefreecaUnit_interface.Add_Command( //상태를 업데이트 하도록 한다. Command_Client.Updated_Connection, new i_Updated_Connection(C.No, i_Updated_Connection_Type.State_Connect, State_Connect.Connected)); process_do_Low(); //모든 크롬 창 최소화. break; } } catch { } if (SideBreak_ConnectNo != -1) //사이드 브레이크 발동 { //if (SideBreak_ConnectNo == C.No) //{ SideBreak_ConnectNo = -1; break; //} } if (timeout_-- <= 0) //0이하면 탈출.. { break; } Thread.Sleep(1000); // 접속을 검사함.. 계속 계속.. 다 될때 까지 다되면 끗. } if (!connected) { if (!none_proxy && timeout > 100) { TefreecaUnit_interface.Add_Command(Command_Client.Change_Proxy, null); } else { if (timeout <= 100) { timeout += 20; } TefreecaUnit_interface.Add_Command( //상태를 업데이트 하도록 한다. Command_Client.Updated_Connection, new i_Updated_Connection(C.No, i_Updated_Connection_Type.State_Connect, State_Connect.Failure)); } } } } catch (Exception ex) { Console.WriteLine("AFREECA ERROR: " + ex.ToString()); TefreecaUnit_interface.Add_Command( //상태를 업데이트 하도록 한다. Command_Client.Updated_Connection, new i_Updated_Connection(C.No, i_Updated_Connection_Type.State_Connect, State_Connect.Failure)); //연결 실패로 바꾼다. } }