无法使用selenium webdriver在Compose E-mail页面上的To(Email id)字段中发送密钥 [英] Unable to send keys within To (Email id) field on Compose E-mail page using selenium webdriver
问题描述
要Buttom 无法从selenium webdriver获取密钥。在输出中,它显示无法定位元素。 To在iframe中,我使用了I frame但是它也没用。
The "To" Buttom is unable to take keys from selenium webdriver. In output it shows Unable to locate element. "To" is in iframe and I have used I frame but then also it not working.
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");
}
}
推荐答案
到发送 Emailid 通过 sendKeys()
方法,您必须先切换回 defaultContent 然后再切换到预期帧与 WebDriverWait 最后诱导 WebDriverWait 为要字段是可交互的,然后发送 EMAILID 如下:
To send the Emailid through sendKeys()
method you have to switch back to the defaultContent first then switch again to the intended frame with WebDriverWait and finally induce WebDriverWait for the To field to be interactable and then send the Emailid as follows :
-
代码阻止:
Code Block :
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");
快照:
Snapshot :
这篇关于无法使用selenium webdriver在Compose E-mail页面上的To(Email id)字段中发送密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!