Selenium Webdriver将电子邮件传递给js表单 [英] Selenium Webdriver pass email to form by js
本文介绍了Selenium Webdriver将电子邮件传递给js表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将电子邮件传递到此表单?
How can I pass email into this form?
您只需要单击专业-开始免费试用",这是我需要使用Selenium Webdriver传递电子邮件的地方.
You need just click "Professional - Start free trial", which is where I need pass email using selenium webdriver.
推荐答案
我注意到用于提供电子邮件的弹出窗口位于不同的框架中.您应该管理上下文切换:
I noticed that the popup for providing your email is in a different frame. You should manage Context switching:
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Email extends BrowserFunctions{
public static void main(String args[]) throws InterruptedException{
System.setProperty("webdriver.chrome.driver", "Drivers//chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.wrike.com/price/");
Thread.sleep(5000);
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", driver.findElement(By.id("start-free-trial-professional")));
Thread.sleep(5000);
driver.switchTo().defaultContent(); // you are now outside both frames
driver.switchTo().frame("ajaxIframeFeatures");
executor.executeScript("arguments[0].setAttribute('value', 'abc@gmail.com');", driver.findElement(By.id("email")));
executor.executeScript("arguments[0].click();", driver.findElement(By.id("start-project")));
Thread.sleep(5000);
}
}
很抱歉使用了太多的Thread.sleep()
,通常这不是一个好习惯.如果要提高性能,可以用WebDriverWait
代替.
Sorry for using too much of Thread.sleep()
, it's not a good practice generally. You can replace it by WebDriverWait
if you want to improve the performance.
我希望它可以帮助:)
这篇关于Selenium Webdriver将电子邮件传递给js表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文