screen page

require "selenium-webdriver" driver = Selenium::WebDriver.for :firefox driver.manage.window.maximize driver.navigate.to "http://www.starofservice.ca/" element = driver.find_element(:xpath, 'html/body/div[1]/div[1]/div/div[2]/a[1]').click element = driver.find_element(:xpath, 'html/body/section/div/div[1]/div/div/div[1]/a').click 

Trying to write a test for the registration of the user. I refer to the element using xpath, but the test fails, writes that it will not find such an element. I tried the options find_element : name ,: link ,: css - does not find it. I tried to write a test version on Python , on Java - the result is the same. Moreover, if I point to an element on the left ( create an account ), everything is OK, it goes without problems every time. And the element create a Professional account does not want. What could be the reason? Link to the page? http://www.starofservice.ca/choose-account

    1 answer 1

     driver.find_element(:xpath, "//a[text()='Registration']").click driver.find_element(:xpath, "//a[text()='Create a Professional account']").click 
    1. Try to use double quotes in the Ruby code, and leave single quotes only for such rare cases as, for example, the second argument [g] sub with the group number.
    2. Layout can travel, and text anchors dictated by the authorities are less volatile, so be attached by *[text()= .
    • Thanks, Nakilon, but, still does not find the item. Did you try to run the test and the button 'Create a Professional account' clicked? - Konstantin
    • @Konstantin, yes, at the time of writing the answer, everything worked. If I don’t forget, I’ll check when I'm behind another computer, in case the layout has suddenly changed on the site. - Nakilon
    • the problem is that during the first test run, the element finds it, with all subsequent tests it does not. It will be possible - try to run the test 2-3 times in a row. - Konstantin
    • Three times drove - everything is ok. - Nakilon