0

I have the following HTML code for a button:

<div class="link" data-background-color="#fb00ff" style="background-color: rgb(251, 0, 255);">
 <div data-replace-selector="paragraph/8429/field_link/en/default" class="field field--name-field-link field--type-link field--label-hidden field__item">
    <a href="/user/login#skip-onboard" style="" xpath="1">Guests</a>
  </div>
</div>
<div data-replace-selector="paragraph/8429/field_link/en/default" class="field field--name-field-link field--type-link field--label-hidden field__item">
  <a href="/user/login#skip-onboard" style="" xpath="1">Guests</a>
</div>
<a href="/user/login#skip-onboard" style="" xpath="1">Guests</a>

And I want to click the button using Selenium Java. What I tried: The following selectors:

  • XPath: //*[@id='block-onboardingblock']/div/div[5]/div/div[2]/div/div/div/a
  • CSS: #block-onboardingblock > div > div.footer-buttons.direction-column > div > div:nth-child(2) > div > div > div > a
  • Full xpath: /html/body/div[3]/div/div/div/div/div[1]/section/div/div/div[5]/div/div[2]/div/div/div/a

Java code:

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].click()", selector); 

or

WebDriverWait wait = new WebDriverWait(webDriver, timeoutInSeconds);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id<locator>));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].click()", selector); 

How I can click the button?

2
  • Could you please edit your post to add HTML including the onboarding block? You might also try adding any errors you receive with your attempts so far.
    – Kate Paulk
    Commented Jun 30, 2023 at 15:51
  • Sure, thank you for the improvement, I don't receive any error, just I saw that the button is not clicked. Also, I add a JavaScript executor with a border to try to understand why it's not clicked.
    – AAa
    Commented Jul 1, 2023 at 10:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.