点击<a href=""> link or get link using Selenium Java

时间:2018-12-21 05:43:37

标签: java swing selenium selenium-webdriver selenium-chromedriver

I am currently developing a system. I am using Selenium WebDriver and language is Java. I have done most of the things but I am stuck at one point. I need to click an activation link using an email. What I need is I need to click the button or get the url to String related to that button. If I can get the url to String it will be really good.

I have attached an image here. I have created a red color rectangle indicating the URL and the button

我是Selenium的新手。我已经尝试过这些方法,但是它们都不起作用,

    WebElement element1 = driver.findElement(By.xpath("//span"));
    element1.click();

    WebElement element2 = driver.findElement(By.linkText("Click here"));
    element2.click();

    WebElement element3 = driver.findElement(By.linkText("Create My Account"));
    element3.click();

    List<WebElement> allLinks = driver.findElements(By.tagName("a"));
    allLinks.get(0).click();

由于激活链接总是不同,所以我也无法使用此方法。

By.xpath("//a[@href='**URL**']") 

那么有人可以帮助我吗?我非常感谢。 谢谢你的帮助。

这是HTML文件,

>  <a
> href="https://store.steampowered.com/account/newaccountverification?stoken=bb0a781e68a4f30374bf6564aef2ab0267a77b32180f86e6c2833e5d50b1ac838f21adc598941d2de8f3bec569af7732&amp;creationid=1511979344947909899"
> style="border-radius: 2px; padding: 1px; display: block;
> text-decoration: none; color: #D2E885; background: #799905;
> background: -webkit-linear-gradient( top, #799905 5%, #536904
> 95%);background: linear-gradient( to bottom, #799905 5%, #536904
> 95%);text-shadow: -1px -1px 0px rgba( 0, 0, 0, 0.1 );"> <span
> style="border-radius: 2px; display: block; padding: 0; font-size:
> 20px; line-height: 32px; ">
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Create My Account&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span> </a>

这是我遇到的一个错误。

  

线程“主要” org.openqa.selenium.NoSuchElementException中的异常:   没有这样的元素:无法找到元素:{“ method”:“ link   文字”,“选择器”:“点击此处”}

0 个答案:

没有答案