“To”Buttom无法从selenium网络驱动程序中获取密钥。在输出中,它显示无法定位元素。“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");
}
}
要通过sendKeys()
方法发送Emailid,您必须先切换回defaultContent,然后使用WebDriver等再次切换到预期的帧,最后诱导WebDriver等To字段可交互,然后按如下方式发送Emailid:
>
代码块:
driver.switchTo().defaultContent();
new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.id("thirdPartyFrame_mail")));
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='compose-header_item compose-header_to mailobjectpanel-objectivation mailobjectpanel-textfield js-component mailobjectpanel']//div[@class='select2-container select2-container-multi js-select2']/ul/li/input"))).sendKeys("abcde@mail.com");
快照: