Selenium webdriver - 选项卡控件 [英] Selenium webdriver - Tab control

查看:40
本文介绍了Selenium webdriver - 选项卡控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目面临挑战.页面中有两个文本框,第一个文本框将接受电子邮件 ID,当用户将其控件从第一个文本框移动到下一个文本框时,电子邮件 ID 将自动填充在第二个文本框中.我需要验证这个测试用例.

I am facing a challenge in my project. There are two text box's in a page and where First text box will accept an email ID and when user move his control to next text box email ID from First text box will populate automatically in the second text box. I need to validate this test case.

我尝试使用以下代码,

WebElement emailElement = driver.findElement(By.id("email"));
emailElement.sendKeys("ABCDEFG@g.com");
WebElement usernameElement = driver.findElement(By.id("username"));
String userName = usernameElement.getAttribute("value");
assertEquals("ABCDEFG@g.com", userName);

有人可以帮助我使用 webdriver java 代码从第二个文本框(用户名)中获取值.

Can someone help me with webdriver java code to fetch value from second text box(username).

提前致谢,

^最好的问候

推荐答案

这个怎么样?

WebElement emailElement = driver.findElement(By.id("email"));
emailElement.sendKeys("ABCDEFG@g.com");

WebElement usernameElement = driver.findElement(By.id("username"));
usernameElement.click(); // Here, autocomplete is done

String userName = usernameElement.getText(); // get the value
assertEquals("ABCDEFG@g.com", userName);

如果你想用 selenium 发送 TAB 键,你可以这样做:

If you want to send the TAB key with selenium, you can do that :

emailElement.sendKeys(Keys.TAB);

此处提供所有特殊键

这篇关于Selenium webdriver - 选项卡控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆