当您在Gmail中撰写电子邮件时,要将电子邮件发送给“联系人”列表中的人员,您必须点击“即可”。它会引导您进入弹出框。有没有办法自动关闭这个盒子?我使用的是Selenium和C#。
答案 0 :(得分:0)
我认为您可能会遇到问题,因为模块化窗口位于iFrame中,您需要告诉Selenium在搜索之前专门查看该iFrame。
请参阅handling-iframes-using-selenium-webdriver。
不幸的是,Google似乎每次创建iframe时都会为此iframe分配一个新ID,因此您无法依赖它,因此您需要为iframe元素创建一个IWebElement并将其传递给.SwithTo()。Frame()调用。
具体来说,你可以尝试这个(我测试了它,它对我有用)。
//Get iFrame element and switch to it.
IWebElement selectContactFrame= driver.FindElement(By.CssSelector("iframe.KA-JQ"));
driver.SwitchTo().Frame(selectContactFrame);
//Find cancel button and click it.
IWebElement cancelButton = driver.FindElement(By.XPath("//div[text()='Cancel']"));
cancelButton.Click();