Join the Stack Overflow Community
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I'm new to learning selenium. I'm just trying to automate a site as a practice. I'm trying www.quikr.com. After the webpage loads it gives a web based pop up i want to select a city in that pop up. I'm unable to select using search by text, ID, xpath.

<a class="cs" index="Ahmedabad" href="javascript:void(0);" onclick="clickcity(this,'bigmodal','ipcity','2','22');">Ahmedabad</a>

On click function is hanadled by this javascript function.

What i want to achieve is how to click one of these links in python using webdriver.

share|improve this question
1  
Use this xpath: //a[contains(text(),'Ahmedabad')]. – Saritha G Jul 16 '15 at 9:16

This example selects 'Ahmedabad'

from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://www.quikr.com")
driver.find_element_by_xpath("//*[@id='ctystlist']/div[1]/div[2]/ul[1]/li[1]/a")
driver.close()

Happy testing!

share|improve this answer

use below code to select chennai option,

FirefoxDriver driver = new FirefoxDriver();

    driver.get("http://www.quikr.com/");

    Wait<WebDriver> wait = new WebDriverWait(driver, 180);
    try {
        wait.until(new ExpectedCondition<WebElement>() {
            public WebElement apply(WebDriver driver) {
                // driver.switchTo().defaultContent();
                WebElement element = driver.findElement(By.xpath("//a[contains(text(),'Chennai')]"));
                if (element.isDisplayed()) {
                    return element;
                }
                return null;
            }
        });
    } catch (Exception e) {
        throw new RuntimeException("Exception while waiting for " + By.xpath("//a[contains(text(),'Chennai')]")
                + ". Exception:" + e + " on " + driver.getCurrentUrl());
    }


    driver.findElement(By.xpath("//a[contains(text(),'Chennai')]")).click();

    driver.close();
share|improve this answer

Your Answer

 
discard

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

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