RE: Help me to locate an weblement

Hi;
Can anyone help me to locate this element.There is a paticular link i want to click.
Firepath gives the xpath as “html/body/section/ul/li/article/div[2]/a/h3” but webdriver can’t find this xpath and it can’t find the css selector also–

driver.findElement(By.cssSelector("#product-popup-list-item > article.product > div.product-title-wrapper > a > h3.title")).click();.

I can’t locate it either by name,link or id.

<a class="" href="/film/abc-26542205">
<h3 class="title"> 300: abc </h3>
<p class="format">(Blu-ray)</p>
</a>

 

Regards.

Priya Train Asked on September 5, 2014 in Selenium WebDriver.
Add Comment
5 Answers
Best answer

HI Priya,

Thanks for bringing this up, as it is something new to us as well.

There is a new technology in the web developement, which is called Lazy Loading. This makes your web page lighter and load fast. How it works is that it loads the page only what is visible on the screen, and on scolling down  the page, it agains loads the rest of the page. So it loads only the visible part of the webpage, not the whole web page as a whole.

So solution to you problem is to scoll down the web page where you element is visible. Make sure you do not scroll it down completely at a go, as if you directly reach to the bottom of the page, then again it will not load the middle web page.

So your intrested element will be active only when you load that part of the page. Hope I made my point clear. Code for your solution:


driver = new FirefoxDriver();

driver.manage().window().maximize();

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

driver.get("URL");

JavascriptExecutor jse = (JavascriptExecutor)driver;

jse.executeScript("window.scrollBy(0,1400)", "");

Thread.sleep(3000);

driver.findElement(By.xpath("/html/body/div[2]/div[2]/div[2]/div[2]/main/section[4]/ul/li[2]/article/div[2]/a")).click();

Or if you see the same element on Chrome browser, it populate some other details about the product, when you mouse hover that product, so at that time you can use the following code:


driver = new FirefoxDriver();

driver.manage().window().maximize();

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

driver.get("URL");

JavascriptExecutor jse = (JavascriptExecutor)driver;

jse.executeScript("window.scrollBy(0,1400)", "");

Thread.sleep(3000);

WebElement element = driver.findElement(By.xpath(".//*[@id='inner-wrapper']/div[2]/main/section[4]/ul/li[2]/article"));

Actions action = new Actions(driver);

action.moveToElement(element).build().perform();

driver.findElement(By.xpath("/html/body/div[2]/div[2]/div[2]/div[2]/main/section[4]/ul/li[2]/article/div[2]/a")).click();

Please mark your question as ANSWERED

Best Regards,
Lakshay Sharma

Professor Answered on September 9, 2014.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.