var webdriver = require ('selenium-webdriver'), { describe, it, after, before } = require('selenium-webdriver/testing'); By = webdriver.By, until = webdriver.until; var driver = new webdriver.Builder().forBrowser('chrome').build(); driver.manage().window().setSize(1280,1000).then(function() { driver.get('http://www.hannaandersson.com/b...; }) driver.manage().timeouts().implicitlyWait(10000)
I've pasted my code here. Sometimes when I run this I get the desired response other times I get no value or I get that the element doesn't exist I don't understand why it works and sometimes it doesn't
neoncont_ joined the channel
hazmeister-sl
firstly, some of the selectors you are using seem kind of brittle: driver.findElement(By.css(‘body > div.ui-dialog.ui-widget.ui-widget-content.ui-corner-all.ui-front.news-content-modal.copy > div.ui-dialog-titlebar.ui-widget-header.ui-corner-all.ui-helper-clearfix > button > span.ui-button-icon-primary.ui-icon.ui-icon-closethick’)).click();
if any of those elements are missing, or are added by javascript, you could end up in a race condition
leb0x
I'm still kind of new to selenium and I don't know a better way outside just selecting the element and doing the copy xpath. This website is done via demandware and is very complicated for elements
hazmeister-sl
try this tutorial for learning about CSS Selectors
I have done that before. I guess I just get lost on this website because things are so deep and confusing. Could you tell me how you'd select one or two of those selectors. That would help me understand a bit more
hazmeister-sl
so, for the modal, I would use `[aria-describedby="QuickViewDialog"]`
[13selenium] 15jleyba pushed 1 new commit to 06master: 02https://git.io/vFL0Y
13selenium/06master 1452a6d68 15Mark Christian: node/selenium-webdriver: increase maximum number of portprober attempts from 10 -> 100 (#4932)...
hazmeister-sl
that was for the modal that pops up after click Quick Buy
if you want the quick buy button, why not `.quickbuy-btn`
ajit joined the channel
leb0x
If I was willing to pay you to help me write tests and show me the best selectors for this one quick buy to teach me best practices would you be interested in that?
hazmeister-sl
I have a full time job already, but you can always seek help on here
it’s busier during the week
leb0x
I understand. I'm a junior web dev and I was told if I can write some tests for this I'd get the job. I just never touched selenium till yesterday
hazmeister-sl
it might be worth finding an online course or buying a book
I would suggest checking a sample chapter before buying
he also offers some free tips via a newsletter
leb0x
oh wow 250
If I get the job ill do it 100%
hazmeister-sl
that’s the version with video- there are cheaper options on there where you get just the book
leb0x
They wanted a basic qa and junior web dev. They are very interested in eventually automating everything. I've spent all day yesterday just getting it to open the quick buy box
hazmeister-sl
there’s also a sample video on writing locators on there
thing is, you’ve jumped in with quite a complicated example there to start with
so you’re off to a good start
leb0x
Thanks for the compliment. I will read his site and sign up. Now I just need to write tests for the stuff in that one quick buy.
So you mentioned `[aria-describedby="QuickViewDialog"]` how would I target the text "Skiers Sweater In Cotton & Merino" with that aria describer?
you’ll want to avoid implicit waits too if you can help it
and you can make findign elements easier by looking within elements
so first thing I would do is find the modal that pops up
and stick it in a var
something like (forgive my javascript):
var newsModal = driver.findElement(By.css(‘’.news-content-modal));
then from there, you can find the close button
leb0x
I tried the close button before
at least when you click it
it opens the hover menu when you click the x
and then it can't find the sweater or quick buy stuff
it was saying its there but isnt't there. Something like that. I tried to sendKey Escape and couldn't get that to work either
hazmeister-sl
very challenging page!
if a sub menu is popping up when you close that modal, you need to use actions to move the cursor somewhere which won’t trigger the pop up
leb0x
yeah man I've struggled all day yesterday just to get to open the quick buy.
so how would you target the close button inside this modal?
hazmeister-sl
so, first find the modal:
var newsModal = driver.findElement(By.css(‘’.news-content-modal));
leb0x
ok
hazmeister-sl
then you can do: newsModal.findElement(By.css(“button[title=‘close’]“))
that way, it’s only looking for close buttons within the context of the modal, instead of the whole page
got it?
sugat-sl joined the channel
leb0x
yeah
it found that element
so would we click it?
btw this is so helpful. idk why I didn't think of finding a whole modal then finding stuff inside it like this
sugat-sl
Selenium Docker Firefox - Firefox 56 gives "Your connection is not secure" error message when trying to run test. And test fails immediately. Any Idea ?
I have selenium version 3.0.1
leb0x
see when I tried to find the button again I get the no such element Unable to locate element: {"method":"css selector","selector":"button[title='close']"} (Session info: chrome=61.0.3163.100)
it worked the first time
hazmeister-sl
could be because that modal doesn’t appear immediately
leb0x
I'm testing it in node right now
with the modal up
this is where I get frustrated with this. The first time I tried it it worked awesome
now I'm in the node terminal with the window open just entering the commands manually
this is why I've been going crazy one minute it works next minute it gives me these errors and idk why. The news modal is up on the screen in the testing envrioment
ajit has quit
Mush joined the channel
Mush
hi
i have installed selenuim ide but i am getting error when I use selenium ide as
@hazmesiter-sl you mentioned waits are bad. How could I wait for the modal to pop up for the newsModal before it starts executing scripts to get away from the sleep
Selenium-Github
[13selenium] 15jleyba pushed 4 new commits to 06master: 02https://git.io/vFL2j