1
String selector = ".rmcAlertDialog .buttons :first-child";
RemoteWebElement selection = (RemoteWebElement) driver.findElement(By.cssSelector(selector));
WebDriverWait wait = new WebDriverWait(driver, 60);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(selection));
if (element == selection) selection.click();

But the element in question (a button) is not responding to the click.

If I click the button manually it works so its not the web page at fault, but the automation.

I have verified the button is there by comparing it's text content.

updated for clarification

This code works (or worked) for most buttons. The code is from a script interpreter which is parsing:-

select ".rmcAlertDialog .buttons :first-child" click

This code was working prior to more recent versions of chrome/selenium/chromedriver.

The code now doesn't work for some buttons.

selection.click() IS being called (verified in a debugger), as element will always equal selection, it just is not working.

.buttons is the class name of the container div for the button(s)

2 Answers 2

2

The selector is not directing to the element with button class. You have a space between .button and :first-child in the selector. Remove the space. The given selector is searching for a child element of the tag with button class. But I'm assuming you are trying to click on the first element with button class not the child node of the button class element. Use this:

String selector = ".rmcAlertDialog .buttons:first-child";
Sign up to request clarification or add additional context in comments.

1 Comment

.buttons is the class name of the containing div
2

I think the main reason it's failing is because your if statement will never be true. I've never done any comparisons like this but you can simplify your code significantly and still get the desired effect.

A few suggestions:

  1. Don't define locators as Strings, define them as Bys. The By class is defined for just such a task and makes using and passing them around MUCH easier.

    String selector = ".rmcAlertDialog .buttons:first-child";
    

    would turn into

    By locator = By.cssSelector(".rmcAlertDialog .buttons:first-child");
    

    Note the correction that S Ahmed pointed out in his answer.

  2. You don't need to find the element to wait for it to be clickable. There is an overload that takes a By locator, use that instead.

    RemoteWebElement selection = (RemoteWebElement) driver.findElement(By.cssSelector(selector));
    WebDriverWait wait = new WebDriverWait(driver, 60);
    WebElement element = wait.until(ExpectedConditions.elementToBeClickable(selection));
    

    becomes

    WebElement element = new WebDriverWait(driver, 60).until(ExpectedConditions.elementToBeClickable(locator));
    
  3. Skip the RemoteWebElement and WebElement comparison. I don't think this will work and there's no need for it anyway. Your locator will locate the same element consistently.

So your final code should look something like

By locator = By.cssSelector(".rmcAlertDialog .buttons:first-child");
new WebDriverWait(driver, 60).until(ExpectedConditions.elementToBeClickable(locator)).click();

1 Comment

Re 1. If you look at my example code it is doing exactly that. Re 2. This is just example code, in reality the first two lines, getting the selection, are elsewhere. Re 3. Correct, as until() will throw an exception if it times out, but that isn't what is causing selection.click() to do nothing, selection.click() is being called, it just isn't doing anything.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.