iframe

 

웹 어플리케이션 적용 : 에디터...

보안 문제 때문에 거부될 수도 있음

 

드라이버에서는 내부의 iframe을 찾을수 없음

포커스를 이동시켜야 함


switchTo()

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class quiz01 {
	public static void main(String[] args)  throws Exception {
		System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
		WebDriver driver = new ChromeDriver();
		WebDriverWait wait = new WebDriverWait(driver,10);
		JavascriptExecutor js = (JavascriptExecutor)driver;
		
		driver.get("https://logins.daum.net/accounts/signinform.do?url=https%3A%2F%2Fwww.daum.net%2F");
		driver.findElement(By.id("id")).sendKeys(Account.id);
		driver.findElement(By.id("inputPwd")).sendKeys(Account.pw);
		driver.findElement(By.id("loginBtn")).click();
		wait.until(ExpectedConditions.urlToBe("https://www.daum.net/"));
		driver.get("https://mail.daum.net/");

		//내가 한 방법 : 메일 이름들이 로딩 될때 까지 대기 , 더 느린듯
		//wait.until(ExpectedConditions.presenceOfElementLocated(By.className("tit_subject")));

		// globalIndicator - 한번 사라짐
		wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id("globalIndicator")));
		//globalIndicator를 활용한 다른 코드
		//wait.until(ExpectedConditions.attributeToBe(By.id("globalIndicator"), "display", "none"));
		List<WebElement> btns = driver.findElements(By.className("btn_my"));
		btns.get(0).click();
		
		
		
		wait.until(ExpectedConditions.presenceOfElementLocated(By.id("mailSubject"))).sendKeys("제목~~~~~~~~~~!!!");
		
		driver.switchTo().frame("tx_canvas_wysiwyg"); // 포커스를 아이프레임으로
		
		driver.findElement(By.tagName("body")).sendKeys("내~~~~~~~~용~~~~~~~~~~~");
		
		
		
		Thread.sleep(5000);
		driver.close(); 
	}
}

보내기 버튼은 외부프레임

 

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class quiz01 {
	public static void main(String[] args)  throws Exception {
		System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
		WebDriver driver = new ChromeDriver();
		WebDriverWait wait = new WebDriverWait(driver,10);
		JavascriptExecutor js = (JavascriptExecutor)driver;
		
		driver.get("https://logins.daum.net/accounts/signinform.do?url=https%3A%2F%2Fwww.daum.net%2F");
		driver.findElement(By.id("id")).sendKeys(Account.id);
		driver.findElement(By.id("inputPwd")).sendKeys(Account.pw);
		driver.findElement(By.id("loginBtn")).click();
		wait.until(ExpectedConditions.urlToBe("https://www.daum.net/"));
		driver.get("https://mail.daum.net/");

		//내가 한 방법 : 메일 이름들이 로딩 될때 까지 대기 , 더 느린듯
		//wait.until(ExpectedConditions.presenceOfElementLocated(By.className("tit_subject")));

		// globalIndicator - 한번 사라짐
		wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id("globalIndicator")));
		//globalIndicator를 활용한 다른 코드
		//wait.until(ExpectedConditions.attributeToBe(By.id("globalIndicator"), "display", "none"));
		List<WebElement> btns = driver.findElements(By.className("btn_my"));
		btns.get(0).click();
		
		
		
		wait.until(ExpectedConditions.presenceOfElementLocated(By.id("mailSubject"))).sendKeys("제목~~~~~~~~~~!!!");
		
		driver.switchTo().frame("tx_canvas_wysiwyg"); // 포커스를 아이프레임으로
		driver.findElement(By.tagName("body")).sendKeys("내~~~~~~~~용~~~~~~~~~~~");
		
		driver.switchTo().defaultContent(); // 포커스를 기본값으로
		List<WebElement> btnWrite= driver.findElements(By.cssSelector(".wrap_toolbar .btn_write"));
		btnWrite.get(0).click();
		
		Thread.sleep(5000);
		driver.close(); 
	}
}

+ Recent posts