- 28 Eki 2022
- 119
- 35
C#:
try
{
IWebDriver driver = new ChromeDriver();
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl("https://www.instagram.com/");
System.Threading.Thread.Sleep(5000);
IWebElement username = driver.FindElement(By.Name("username"));
username.SendKeys(textBox1.Text);
System.Threading.Thread.Sleep(5000);
IWebElement password = driver.FindElement(By.Name("password"));
password.SendKeys(textBox2.Text);
System.Threading.Thread.Sleep(5000);
IWebElement LoginButton = driver.FindElement(By.CssSelector("button[type='submit']"));
LoginButton.Click();
System.Threading.Thread.Sleep(7000);
IWebElement notnow = driver.FindElement(By.XPath("/html/body/div[2]/div/div/div[2]/div/div/div/div[1]/div[1]/div[2]/section/main/div/div/div/div/div"));
notnow.Click();
System.Threading.Thread.Sleep(5000);
IWebElement notnow1 = driver.FindElement(By.XPath("//button[contains(text(), 'Şimdi Değil')]"));
notnow1.Click();
System.Threading.Thread.Sleep(10000);
IWebElement ReelsClick = driver.FindElement(By.XPath("/html/body/div[2]/div/div/div[2]/div/div/div/div[1]/div[1]/div[1]/div/div/div/div/div[2]/div[4]/div/a/div"));
ReelsClick.Click();
System.Threading.Thread.Sleep(5000);
while(true)
{
IWebElement CommentButton = driver.FindElement(By.CssSelector("svg[aria-label='Yorum'][height='24']"));
CommentButton.Click();
System.Threading.Thread.Sleep(2000);
try
{
IWebElement Comment = driver.FindElement(By.CssSelector("textarea[placeholder='Yorum ekle...']"));
Comment.Click();
System.Threading.Thread.Sleep(1000);
Comment = driver.SwitchTo().ActiveElement();
Comment.SendKeys("test");
System.Threading.Thread.Sleep(2000);
IWebElement Send = driver.FindElement(By.XPath("/html/body/div[2]/div/div/div[2]/div/div/div/div[2]/div/div/div[1]/div[1]/div/div/div/div[1]/div/div[3]/div/section/div/form/div/div[2]/div"));
Send.Click();
System.Threading.Thread.Sleep(7000);
IWebElement Close = driver.FindElement(By.CssSelector("svg[aria-label='Kapat'][class='x1lliihq x1n2onr6']"));
Close.Click();
}
catch (Exception)
{
System.Threading.Thread.Sleep(5000);
IWebElement Close = driver.FindElement(By.CssSelector("svg[aria-label='Kapat'][class='x1lliihq x1n2onr6']"));
Close.Click();
}
//ÇALIŞMAYAN KISIM
System.Threading.Thread.Sleep(7000);
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
Actions actions = new Actions(driver);
js.ExecuteScript("window.scrollBy(0, document.body.scrollHeight)");
}
}
catch (Exception ex)
{
MessageBox.Show("PROGRAM YANIT VERMİYOR!!!\n" + ex.Message);
}
Yukarıda selenium ile sırasıyla:
-İnstagrama giren
-Kullanıcı adı ve passwordunu giren
-girisyap butonuna tıklayan
-karsısına cıkan 'Giriş bilgileri kaydedilsinmi' ve 'Bildirimler aktifleştirilsinmi' sorusuna şimdi değil yanıtı veren
-sayfanında solunda yer alacak olan reelse tıklayan
-ve de yorum yapan
bir kod var. Ancak yorum kutucugunu kapattıktan sonra tekrardan yorum butonuna tıklayıp yorum yapıyor.
sonda yer alan sayfayı assagı kaydırmak için kullanılan kodu görmüyor
C#:
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
Actions actions = new Actions(driver);
js.ExecuteScript("window.scrollBy(0, document.body.scrollHeight)");