How to click anchor tag using Selenium WebDriver


Shubham Mishra:

I can't click the button with some visibility issues. I need to hover over the link before clicking the same link.

<a tabindex="0" 
   class="cardPreviewLink expand-icon" 
   aria-label="card opens in new tab" 
   target="_blank" 
   id="card-preview-link-19479" 
   href="/card/19479?$filters@$pattern=10532372&amp;type===&amp;dimension=chargeback_id"> 
  <button class="MuiButtonBase-root MuiIconButton-root" tabindex="-1" type="button">
    <span class="MuiIconButton-label">
      <svg class="MuiSvgIcon-root open-icon" 
           focusable="false" 
           viewBox="0 0 24 24" 
           aria-hidden="true" 
           role="presentation">
        <path d="M19 19H5V5h7V3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2v-7h-2v7zM14 3v2h3.59l-9.83 9.83 1.41 1.41L19 6.41V10h2V3h-7z"/>
      </svg>
    </span>
  </button>
</a>

Code trial:

WebDriverWait wait4 = new WebDriverWait(driver, 60);
wait4.until(ExpectedConditions.visibilityOfElementLocated(By.className("cardPreviewLink expand-icon")));
driver.findElement(By.className("cardPreviewLink expand-icon")).click();

mistake:

Timeout Exception because of No such Element Exception
Muzzamil

You can try using clickable webdriver wait.element to receive click

By buttonBy = By.cssSelector("a.cardPreviewLink.expand-icon > button"));

WebDriverWait wait = new WebDriverWait(driver, 50);
wait.until(ExpectedConditions.elementToBeClickable(buttonBy);

If the above method doesn't work, you can try it click using JS. Here I'm just waiting, visibility of elementif the element can receive clicks, the first method should work.

wait.until(ExpectedConditions.visibilityOfElementLocated(buttonBy);

WebElement button=driver.findElement(buttonBy);

JavascriptExecutor executor = (JavascriptExecutor)driver;

executor.executeScript("arguments[0].click();", button);

Related


How to click anchor tag using Selenium WebDriver

Shubham Mishra: I can't click the button with some visibility issues. I need to hover over the link before clicking the same link. <a tabindex="0" class="cardPreviewLink expand-icon" aria-label="card opens in new tab" target="_blank" id="card-p

How to click anchor tag using Selenium WebDriver

Shubham Mishra: I can't click the button with some visibility issues. I need to hover over the link before clicking the same link. <a tabindex="0" class="cardPreviewLink expand-icon" aria-label="card opens in new tab" target="_blank" id="card-p

How to click anchor tag using Selenium WebDriver

Shubham Mishra: I can't click the button with some visibility issues. I need to hover over the link before clicking the same link. <a tabindex="0" class="cardPreviewLink expand-icon" aria-label="card opens in new tab" target="_blank" id="card-p

How to click anchor tag using Selenium WebDriver

Shubham Mishra: I can't click the button with some visibility issues. I need to hover over the link before clicking the same link. <a tabindex="0" class="cardPreviewLink expand-icon" aria-label="card opens in new tab" target="_blank" id="card-p

How to click anchor tag using Selenium WebDriver

Shubham Mishra: I can't click the button with some visibility issues. I need to hover over the link before clicking the same link. <a tabindex="0" class="cardPreviewLink expand-icon" aria-label="card opens in new tab" target="_blank" id="card-p

selenium webdriver find anchor tag and click

Sathish Kumar kk <div id="ContentPrimary"> <ul class="selectors modeSelectors"> <li><a href="/content/l411846326l1213g/references/" title=""> <span class="selector">References (27)</span></a></li> <li><a href="/content/l411846326l1213g/referrer

selenium webdriver find anchor tag and click

Sathish Kumar kk <div id="ContentPrimary"> <ul class="selectors modeSelectors"> <li><a href="/content/l411846326l1213g/references/" title=""> <span class="selector">References (27)</span></a></li> <li><a href="/content/l411846326l1213g/referrer

selenium webdriver find anchor tag and click

Sathish Kumar kk <div id="ContentPrimary"> <ul class="selectors modeSelectors"> <li><a href="/content/l411846326l1213g/references/" title=""> <span class="selector">References (27)</span></a></li> <li><a href="/content/l411846326l1213g/referrer

selenium webdriver find anchor tag and click

Sathish Kumar kk <div id="ContentPrimary"> <ul class="selectors modeSelectors"> <li><a href="/content/l411846326l1213g/references/" title=""> <span class="selector">References (27)</span></a></li> <li><a href="/content/l411846326l1213g/referrer

How to click it using selenium webdriver?

Nickett I have an element like this: <a class="btn">Select</a> How to click this using selenium webdriver? Durban B To be on a link with click()the text Select , you can use any of the following options: python link_text: driver.find_element_by_link_text("Sele

How to click an element in Selenium WebDriver using JavaScript

Ripon Al Wasim: I have the following HTML: <button name="btnG" class="gbqfb" aria-label="Google Search" id="gbqfb"><span class="gbqfi"></span></button> My code below for clicking the "Google Search" button works fine using Java in WebDriver. driver.findElemen

How to double click an element using Selenium Webdriver

Saravana This is a dynamic listing on our website. This is the HTML tag I want to pass double click. <td class="dxgv" align="left" style="color: rgb(51, 51, 51); font-size: 13px; border-bottom: 1px solid rgb(237, 237, 237); border-left-width: 0px; border-right

How to double click an element using Selenium Webdriver

Saravana This is a dynamic listing on our website. This is the HTML tag I want to pass double click. <td class="dxgv" align="left" style="color: rgb(51, 51, 51); font-size: 13px; border-bottom: 1px solid rgb(237, 237, 237); border-left-width: 0px; border-right

How to click a link using Selenium WebDriver

Wallip How can I use selenium webdriverget all links from a page with attributes a[href*=/simulation/form/]and then open and close each link? I tried the following code but it returnedTypeError: link.click is not a function var simLinks = driver.findElements(B

How to click an image using Selenium WebDriver

Swathi Jeedula I'm new to selenium and can't click on the image named "Register" highlighted in the attached screenshot. Can anyone let me know why the web element is not recognized at runtime and how to recognize it and click it? import java.io.FileInputStrea

How to click an element in Selenium WebDriver using JavaScript

Ripon Al Wasim: I have the following HTML: <button name="btnG" class="gbqfb" aria-label="Google Search" id="gbqfb"><span class="gbqfi"></span></button> My code below for clicking the "Google Search" button works fine using Java in WebDriver. driver.findElemen

How to double click an element using Selenium Webdriver

Saravana This is a dynamic listing on our website. This is the HTML tag I want to pass double click. <td class="dxgv" align="left" style="color: rgb(51, 51, 51); font-size: 13px; border-bottom: 1px solid rgb(237, 237, 237); border-left-width: 0px; border-right

How to click a link using Selenium WebDriver

Wallip How can I use selenium webdriverget all links from a page with attributes a[href*=/simulation/form/]and then open and close each link? I tried the following code but it returnedTypeError: link.click is not a function var simLinks = driver.findElements(B

How to click a link using Selenium WebDriver

Wallip How can I use selenium webdriverget all links from a page with attributes a[href*=/simulation/form/]and then open and close each link? I tried the following code but it returnedTypeError: link.click is not a function var simLinks = driver.findElements(B

How to click an image using Selenium WebDriver

Swathi Jeedula I'm new to selenium and can't click on the image named "Register" highlighted in the attached screenshot. Can anyone let me know why the web element is not recognized at runtime and how to recognize it and click it? import java.io.FileInputStrea

How to click an image using Selenium WebDriver

Swathi Jeedula I'm new to selenium and can't click on the image named "Register" highlighted in the attached screenshot. Can anyone let me know why the web element is not recognized at runtime and how to recognize it and click it? import java.io.FileInputStrea

How to click an image using Selenium WebDriver

Swathi Jeedula I'm new to selenium and can't click on the image named "Register" highlighted in the attached screenshot. Can anyone let me know why the web element is not recognized at runtime and how to recognize it and click it? import java.io.FileInputStrea

How to click an image using Selenium WebDriver

Swathi Jeedula I'm new to selenium and can't click on the image named "Register" highlighted in the attached screenshot. Can anyone let me know why the web element is not recognized at runtime and how to recognize it and click it? import java.io.FileInputStrea

How to click an element using Selenium Webdriver JavaScript?

Christian Zagonni I'm testing and the element has to be clicked, but sometimes it clicks, sometimes it doesn't. I've tried a few solutions, but none of them always click. Is there any solution to click on an element that always works? I tried the following cod