51Testing软件测试论坛
标题:
selenium webdriver定位ajax网站iframe内元素出错
[打印本页]
作者:
gymhangel
时间:
2014-5-12 11:22
标题:
selenium webdriver定位ajax网站iframe内元素出错
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class FirstExample {
public static void main(String[] args) throws Exception {
WebDriver driver = new FirefoxDriver();
driver.get("http://192.168.2.39/qlikview/index.htm");
Thread.sleep(2000);
driver.findElement(By.id("userName")).clear();
driver.findElement(By.id("userName")).sendKeys("test");
driver.findElement(By.id("pass")).clear();
driver.findElement(By.id("pass")).sendKeys("test");
driver.findElement(By.className("loginSubmit")).click();
driver.get("http://192.168.2.39/QvAJAXZfc/opendoc.htm?document=QlikSales%20Fashion%20Phase%202%201104.qvw&host=QVS@view");
driver.switchTo().frame("popupFrame1");
driver.findElement(By.tagName("userid")).sendKeys("admin");
driver.findElement(By.tagName("password")).sendKeys("admin");
driver.switchTo().defaultContent();
driver.close();
}
复制代码
出错如下:Exception in thread "main" org.openqa.selenium.UnhandledAlertException: Modal dialog present: Login Failed
Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:18:15'
System info: host: 'yangxi', ip: '192.168.0.116', os.name: 'Windows 8', os.arch: 'amd64', os.version: '6.2', java.version: '1.6.0_43'
Session ID: 5af9ca81-bcd3-4501-9262-588c6649a00d
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, browserName=firefox, rotatable=false, locationContextEnabled=true, version=29.0.1, cssSelectorsEnabled=true, databaseEnabled=true, handlesAlerts=true, browserConnectionEnabled=true, nativeEvents=false, webStorageEnabled=true, applicationCacheEnabled=true, takesScreenshot=true}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)
at org.openqa.selenium.remote.ErrorHandler.createUnhandledAlertException(ErrorHandler.java:174)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:141)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:595)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.frame(RemoteWebDriver.java:862)
at FirstExample.main(FirstExample.java:19)
登陆的用户名密码都没有错误啊,手动输入没问题,但是自动化输入就是没办法实现。求指教。
作者:
larryrelax
时间:
2014-5-20 17:28
从错误信息来看,有个模态窗口你没有处理。
试下:webdirver.switchTo.alert();
作者:
liuliu022004
时间:
2014-6-16 14:46
本帖最后由 liuliu022004 于 2014-6-16 15:53 编辑
selenium buildin关键字有一个 switch_to_frame()
必须一层一层select到元素所在的iframe才能找到元素
view source找到它所在的iframe
看不懂java猜测应该和我以前一个问题
例如:
self._current_browser()。switch_to_default_content()
self._current_browser().switch_to_frame(“firstleveliframe”)
self._current_browser().switch_to_frame(“secondleveliframe”)
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2