我的body标签带有属性,我需要在Selenium WebDriver测试中获取断言的电子邮件地址。它能通过默认定位器进行吗?
<body ng-init=" user={"id":43,"email":"EMAIL@gmail.com","username":"USER_NAME","balance":2259,"location":null,"d
escription":null,"fullname":"FULL_NAME","notification_settings":
{"newsletter":true,"follower":true,"mention":true,"comment":true},"settings":{"nsfw":false}};
user.small_avatar_url ='http://cdn.stage.uprise.com/user/43/small_34_34_20131111162316735';
" ng-class="(notice) ? 'with-notice' : ''" data-twttr-rendered="true" class="">
解决方案对我来说有用的工具是:
String nginit = this.getBrowser().findElement(By.tagName("body")).getAttribute("ng-init");
String[] arr = nginit.split(",");
for ( String ss : arr) {
if(ss.contains("email")) {
String[] email = ss.split("\"");
this.loggedinEmail = email[3];
}
}
答案 0 :(得分:2)
由于电子邮件是“ 正文 ”标记的属性“ ng-init ”的部分值。我建议在Body标签的帮助下构造元素,然后检索“ng-init”元素。
稍后您可以解析字符串,以验证/使用电子邮件。
String Input= Driver.FindElement(By.ByTagName("Body")).getAttribute("ng-init");
然后使用字符串标记生成器解析它,如下所示
StringTokenizer tokens=new StringTokenizer(Input,",");
String temp=null;
String Email=null;
while(tokens.hasMoreTokens()){
temp=tokens.nextToken();
if(temp.contains("email")){
Email=temp.split("\"")[3];
System.out.println(Email);
break;
}
答案 1 :(得分:-1)
我不确定试试这个..
option=driver.find_element_by_class_name("")
email=option.get_attribute("email")