Internet explorer Gmail登录按钮在IE8中未被Selenium识别
我正在WindowsXP/IE8中为Gmail登录执行Selenium/TestNG脚本。脚本在该页面中输入正确的用户ID和密码,但它并没有点击Gmail中的“登录”选项 我在Windows7/IE9上运行了相同的脚本,它运行正常。同样的脚本也适用于Firefox。请告知 Selenium版本:2.25.0Internet explorer Gmail登录按钮在IE8中未被Selenium识别,internet-explorer,selenium-webdriver,testng,Internet Explorer,Selenium Webdriver,Testng,我正在WindowsXP/IE8中为Gmail登录执行Selenium/TestNG脚本。脚本在该页面中输入正确的用户ID和密码,但它并没有点击Gmail中的“登录”选项 我在Windows7/IE9上运行了相同的脚本,它运行正常。同样的脚本也适用于Firefox。请告知 Selenium版本:2.25.0 import org.testng.annotations.*; import org.openqa.selenium.*; import org.openqa.selenium.ie.*;
import org.testng.annotations.*;
import org.openqa.selenium.*;
import org.openqa.selenium.ie.*;
public class New_Booking_Inc {
private WebDriver driver;
private String baseUrl;
@BeforeTest
public void Open_IE() throws Exception {
System.setProperty("webdriver.ie.driver", "C:\\WINDOWS\\system32");
driver = new InternetExplorerDriver();
baseUrl = "http://www.gmail.com";
driver.get(baseUrl);
}
@Test (testName = "Login")
public void Login() throws Exception {
//driver.get(baseUrl);
driver.findElement(By.id("Email")).clear();
driver.findElement(By.id("Email")).sendKeys("extsc2");
Thread.sleep(1000);
driver.findElement(By.id("Passwd")).clear();
driver.findElement(By.id("Passwd")).sendKeys("Passwords");
Thread.sleep(1000);
driver.findElement(By.id("signIn")).click();
Thread.sleep(5000);
}
@AfterTest
public void Close_IE() throws Exception {
driver.quit();
}
}
IE存在一些已知问题,其中.click()无法正常工作 您是否尝试过:
driver.findElement(By.id("signIn")).SendKeys("\n");
试试看
driver.findElement(By.id(“sign”)).sendKeys(key.ENTER)
或者使用不同的xpath“”您是否尝试使用By.Name(“signIn”)如果它也不起作用,请尝试在webdriver中使用waitforelementpresent命令,然后单击使用id或名称的按钮。您确实不想尝试自动化GMail。它是网络上最复杂的应用之一。每个人都在尝试这条学习之路,但这条路充满了泪水。@HemChe我尝试过通过名称识别元素,但仍然没有运气。我不知道如何使用waitforelementpresent,我是硒新手。我在其他人的系统中尝试过,脚本运行良好。我所确定的是,由于1152x864号决议(仅在我的系统中),它失败了。我在我的系统中更改了分辨率1024x768,然后它工作了。我不知道为什么只有在我的系统中才会发生这种情况。@我正在使用的RossPatterson应用程序具有带有用户id和密码的登录页。当时我在gmail中试过,但这不起作用,因为它的代码有点类似。@AbdulHameed要执行selenium脚本,据我所知,浏览器的缩放级别应该是100%。所以这可能就是问题所在。有人,如果我错了,请纠正我。谢谢@Anand,它正在按照您的评论工作。如果我的系统分辨率为1024x768,则Click()也可以工作。谢谢@kkdjfl,它可以根据您的评论工作。如果我的系统分辨率为1024x768,则Click()也可以工作。