【发布时间】:2018-04-04 10:30:26
【问题描述】:
“To”按钮无法从 selenium webdriver 获取密钥。在输出中显示无法定位元素。 “To”在 iframe 中,我使用了 I frame,但它也无法正常工作。
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class mail {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.gecko.driver", "D:\mozilla driver\geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.get("https://www.mail.com/int/");
driver.findElement(By.xpath(".//*[@id='login-button']")).click();
driver.findElement(By.xpath(".//*[@id='login-email']")).sendKeys("rahulrahulxyz@mail.com");
driver.findElement(By.xpath(".//*[@id='login-password']")).sendKeys("incredible");
driver.findElement(By.xpath(".//*[@id='login-form']/button")).click();
driver.switchTo().frame("thirdPartyFrame_home");
driver.findElement(By.linkText("Compose E-mail")).click();
Thread.sleep(5000);
driver.switchTo().frame("thirdPartyFrame_mail"); // **here is error**
driver.findElement(By.xpath(".//*[@id='idbd']/div[2]/div[1]/div[1]/div[2]/div/div/ul/li/input")).sendKeys("abcde@mail.com");
}
}
【问题讨论】:
-
如果是帧中的分层顺序,则需要切换到父帧->然后是子帧。看看这个答案是否对你有帮助stackoverflow.com/a/40759300/2575259
标签: java selenium selenium-webdriver iframe webdriver