how to find 'first child' element with Javascript+selenium+node+cucumber

149 views
Skip to first unread message

Damita stathakis

unread,
Nov 1, 2016, 7:32:29 PM11/1/16
to Selenium Users
Hi,

I'm new to Javascript and Selenium so please bear with me!

How would I locate the element 'Accept' and click it?









I have tried a few combinations and I am currently on this:

driver.findElement(By.css("button.dialog-button.eula-button")).click();

But I get the no such element error.

Thanks for any help!

viren patel

unread,
Nov 1, 2016, 9:58:39 PM11/1/16
to Selenium Users
WebElement acceptText = driver.findElement(By.xpath(".//button[contains(text(),'Accept')]"));
acceptText.click();

Anupam Tiwari

unread,
Nov 2, 2016, 5:52:12 AM11/2/16
to seleniu...@googlegroups.com
Hi,
try below;

List<WebElement> buttons= driver.findElements(By.className("dialog-button eula-button"));

for(int i=0; i<buttons.size(); i++){
WebElement button=buttons.get(i);
String buttonName=button.getText();
if(buttonName.equals("Accept")){
button.click();
}
}
}

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/bcae030c-7c23-4eb2-b373-432c8feb61bb%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Damita stathakis

unread,
Nov 2, 2016, 7:12:45 AM11/2/16
to Selenium Users
Thanks for your reply!  Still not having any luck with the xpath locator :(

Is this Java?  I using javascript...maybe the xpath locators are different syntax?

Damita stathakis

unread,
Nov 2, 2016, 7:32:27 AM11/2/16
to Selenium Users
Thanks for the help but I'mn ot having much luck with this either, although I have written it in Javascript, did you use Java?  

I tried this:
buttons = driver.findElement(By.className("eula-button"));

but I cannot call buttons.length, I assumed it would be an array of elements.

Frustrating!

On Wednesday, 2 November 2016 09:52:12 UTC, Anupam Tiwari wrote:
Hi,
try below;

List<WebElement> buttons= driver.findElements(By.className("dialog-button eula-button"));

for(int i=0; i<buttons.size(); i++){
WebElement button=buttons.get(i);
String buttonName=button.getText();
if(buttonName.equals("Accept")){
button.click();
}
}
}
On Wed, Nov 2, 2016 at 7:28 AM, viren patel <patel.v...@gmail.com> wrote:
WebElement acceptText = driver.findElement(By.xpath(".//button[contains(text(),'Accept')]"));
acceptText.click();

On Tuesday, November 1, 2016 at 6:32:29 PM UTC-5, Damita stathakis wrote:
Hi,

I'm new to Javascript and Selenium so please bear with me!

How would I locate the element 'Accept' and click it?









I have tried a few combinations and I am currently on this:

driver.findElement(By.css("button.dialog-button.eula-button")).click();

But I get the no such element error.

Thanks for any help!

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

Abhishek Shama

unread,
Nov 3, 2016, 10:30:00 AM11/3/16
to Selenium Users
 Is this Accept and Decline elements are appearing on popup window ?

Nadia García

unread,
Nov 4, 2016, 12:09:49 AM11/4/16
to Selenium Users
driver.findElement will retrieve the first element matching the criteria. 
If you want a list of the items matching the criteria use driver.findElements
Reply all
Reply to author
Forward
0 new messages