How to click a href link using Selenium

前端 未结 10 1225
悲哀的现实
悲哀的现实 2020-12-09 09:48

I have a html href link

App Configuration

using Selenium I need

相关标签:
10条回答
  • 2020-12-09 10:29

    How to click on link without using click method in selenum?

    This is a tricky question. Follow the below steps:

    driver.get("https://www.google.com");
    String gmaillink= driver.findElement(By.xpath("//a[@href='https://mail.google.com/mail/?tab=wm&ogbl']")).getAttribute("href");
    System.out.println(gmaillink);
    driver.get(gmaillink);
    
    0 讨论(0)
  • 2020-12-09 10:29

    You can use xpath as follows, try this one :

    driver.findElement(By.xpath("(.//[@href='/docs/configuration'])")).click();
    
    0 讨论(0)
  • 2020-12-09 10:34

    Use an explicit wait for the element like this:

    WebDriverWait wait1 = new WebDriverWait(driver, 500);
    wait1.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("path of element"))).click();
    
    0 讨论(0)
  • 2020-12-09 10:39

    Use

    driver.findElement(By.linkText("App Configuration")).click()
    

    Other Approaches will be

    JavascriptLibrary jsLib = new JavascriptLibrary(); 
    jsLib.callEmbeddedSelenium(selenium, "triggerMouseEventAt", elementToClick,"click", "0,0");
    

    or

    ((JavascriptExecutor) driver).executeScript("arguments[0].click();", elementToClick);
    

    For detailed answer, View this post

    0 讨论(0)
  • 2020-12-09 10:39

    Try to use Action class to reach the element

    Actions action = new Actions(driver);
    action.MoveToElement(driver.findElement(By.xpath("//a[text()='AppConfiguration']")));
    action.Perform();
    
    0 讨论(0)
  • 2020-12-09 10:40

    You can use this method:

    For the links if you use linkText(); it is more effective than the any other locator.

    driver.findElement(By.linkText("App Configuration")).click();
    
    0 讨论(0)
提交回复
热议问题