-1

I have requirement that needs to check a div on home page that contains sub images. I am trying like this

My Sample Code :

module.exports.openurl('www.google.com', "Online Shopping | Buy Phones, Computers,Fashion");
driver.sleep(5000);
module.exports.scrollto(0,400);          
driver.isElementPresent(webdriver.By.xpath(fexpath)).then(function(present){
    if (present){
        //goes logic here
    }else{
        //everytime its going here                
    }

Here I am getting false as return value. I'm not sure what I'm doing wrong.

  • 2
    Please provide the full code and the HTML. – FDM Mar 4 '15 at 7:45
  • are you sure fexpath exists? Are you really saying that if you comment out the module.exports.scrollto(0,400);, it works? That sounds dubious to me . . . – ernie Mar 4 '15 at 23:56
0

Thanks for your suggestions Guys

I have solved my problem by using the javascript executor. Below is the code:

var element = driver.findElement(webdriver.By.xpath(xpath));
driver.executeScript("arguments[0].scrollIntoView(true);", element);
-1

U should try scroll to element. it is in api. Element should be visible to interact with it.

also check:

  1. Did it occurs when windows is maximized?
  2. Did it work with css locator?
  3. Is it browser dependent?(on all drivers or specific one).
  • 2
    -1 because: grammar, composition, sense. Please try and correct your answer and clarify what you mean by it. – Hannibal Mar 4 '15 at 10:07
-1

Best practices recommend to use XPath as locator of last resort. Did you tried locating element by ID or name? Or even CSS?

  • Citation of best practices describing XPath as 'last resort'? – Lucas Schwarz Mar 4 '15 at 21:58
  • see link added. – Peter M. Mar 4 '15 at 22:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.