我们如何单击Selenium Webdriver下的“ Href”链接?

时间:2019-03-08 11:13:04

标签: selenium selenium-webdriver selenium-chromedriver

我想按附件图像单击href链接,并且我尝试了以下代码,但似乎无法正常工作。请帮助我。

.....

driver.findElement(By.xpath(“ // a [@ href ='Careers']”)))。click();

............

以下是Div标签的HTML内容... ..............

    <div class="logo">
        <img src="/ui/healthcare/assets/images/core/ascension_logo_white.svg" alt="Ascension">
    </div>


    <ul class="list-group">
            <li>
                <h4>Get Involved</h4>
                <ul class="link-list">
                            <li><a href="/Careers">Careers</a></li>
                            <li><a href="/Events">Classes and Events</a></li>

........................

..... enter image description here

enter image description here

1 个答案:

答案 0 :(得分:1)

在xpath下尝试此

 driver.get("https://healthcare.ascension.org/"); 
JavascriptExecutor js = ((JavascriptExecutor) driver); 
js.executeScript("window.scrollTo(0, document.body.scrollHeight)"); 
JavascriptExecutor executor = (JavascriptExecutor) driver; 
executor.executeScript("arguments[0].click();",driver.findElement(By.xpath("//a[@href='/Careers']")));