1

I want to click the load More link in a page. My code is below.

pageUrl="http://www.foundpix.com/category/actor/bollywood-actor/"

WebDriver driver = new FirefoxDriver();

driver.get(pageUrl);

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

JavascriptExecutor jse = (JavascriptExecutor) driver;

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

WebDriverWait wait = new WebDriverWait(driver, 60);

wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("json_click_handler")));

driver.findElement(By.id("json_click_handler")).click();

How can I make it click the link.

3 Answers 3

2

You can use below xpath to click Load More button both the times:-

driver.findElement(By.xpath("//*[@id='blocks-left']/div/div[3]/div[contains(.,'Load More')]")).click();
Sign up to request clarification or add additional context in comments.

Comments

0

this button change the location after you click on it and it can be clicked twice so:

before the first click use

driver.findElement(By.xpath("//*[@id="blocks-left"]/div/div[3]/div")).click();

after first click,you can use

driver.findElement(By.xpath("//*[@id="blocks-left"]/div/div[3]/div[2]")).click();

Comments

0

Maybe come at it from a different angle. Do you really need to have the link clicked or do you have some Javascript function that gets called on click of the link (like window.loadMore). Can you call the function directly? Selenium is a bit annoying in the sense you can only click a visible element (I don't mean it has to be in the viewport - it just can't have a style like display:none;).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.