如何在外部div内使用带有标签警报的元素定位 [英] How to locate element with tag alert inside outer div

查看:153
本文介绍了如何在外部div内使用带有标签警报的元素定位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在,但它也无法正常工作

I trying to locate elemnts in this page and put it in Objects (DomElement) to making some tests of it, the problem is with elemnt reg-error-yid it is a inner-div inside div yid-field-suggestion, I tried to getElementById, byName, byXPath, and getFirstByXPath it's all not working , also I tried to change webClient with WebDriver and use driver.findElement(By.className("oneid-error-message")) it's also not working

已注册邮件的内容

<div id="reg-error-yid" class="oneid-error-message" data-error="messages.IDENTIFIER_EXISTS" role="alert">A Yahoo account already exists with this email address. <a href="https://login.yahoo.com/?intl=xa&amp;lang=en-JO&amp;src=ym&amp;.intl=xa&amp;specId=yidReg&amp;.done=https%3A%2F%2Fmail.yahoo.com&amp;nr=1&amp;step=2&amp;.crumb=qP.UnkGzfkR&amp;login=abtallaldigital">Sign in</a>.</div>

我的代码

final HtmlPage page1 = webClient.getPage("https://login.yahoo.com/account/create?specId=yidReg&lang=en-JO&src=ym&done=https%3A%2F%2Fmail.yahoo.com&display=login&intl=xa");

             final DomElement firstName = page1.getElementById("usernamereg-firstName");
             final DomElement emailAddress = page1.getElementById("usernamereg-yid");
             final DomElement takenMsg = page1.getElementById("reg-error-yid");

推荐答案

我不确定您的需求.我不能在这里发表评论.

I am not sure about your need. I can't comment here.

但是,如果您尝试解析文档,则可以使用 Jsoup 来解析文档.

But if you are trying to parse the document you can use Jsoup for parsing the document.

getElementById, byName, byXPath相比,select更有用和更容易.

The select is more useful and easy as compared to getElementById, byName, byXPath.

org.jsoup.nodes.Document doc = Jsoup.connect("https://login.yahoo.com/account/create?specId=yidReg&lang=en-JO&src=ym&done=https%3A%2F%2Fmail.yahoo.com&display=login&intl=xa").get();
org.jsoup.select.Elements takenMsgs = doc.select("div[id=reg-error-yid]");
org.jsoup.select.Element takenMsgFirst = doc.select("div[id=reg-error-yid]").first;

查看是否可以将org.jsoup.select.Elements转换为com.gargoylesoftware.htmlunit.html.DomElement

See if you can convert org.jsoup.select.Elements to com.gargoylesoftware.htmlunit.html.DomElement

这篇关于如何在外部div内使用带有标签警报的元素定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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