2

Code Trials:

from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://www.niftyindices.com/reports/historical-data")
driver.maximize_window()
driver.find_element_by_xpath("//*[@id="ddlHistorical"]").send_keys("NIFTY 100")

I am getting an error:

File "<ipython-input-32-592f058980cd>", line 5
    driver.find_element_by_xpath("//*[@id="ddlHistorical"]").send_keys("NIFTY 100")
                                                       ^
SyntaxError: invalid syntax

2 Answers 2

3

This error message...

SyntaxError: invalid syntax

...implies that the xpath expression was not a valid xpath expression.

As you are using double quotes i.e. "..." for the xpath you need to provide the attribute values within single quotes i.e. '...'.

So you need to change:

@id="ddlHistorical"

To:

@id='ddlHistorical'

Effectively the line of code:

driver.find_element_by_xpath("//*[@id="ddlHistorical"]").send_keys("NIFTY 100")

will be:

driver.find_element_by_xpath("//*[@id='ddlHistorical']").send_keys("NIFTY 100")
Sign up to request clarification or add additional context in comments.

Comments

2

Send Keys can not be used in this case to select the value from drop down box:

import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;

public class Testing {
	public static WebDriver driver;

	@Test
	public void test() throws InterruptedException {
		System.setProperty("webdriver.chrome.driver", "./Driver/chromedriver");
		driver = new ChromeDriver();
		driver.get("http://www.niftyindices.com/reports/historical-data");
		driver.manage().window().maximize();
		driver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//*[@id=\"HistoricalData\"]/div[1]/div/div/a")).click();
		Thread.sleep(2000);
		List<WebElement> elements = driver.findElements(By.xpath("//*[@id=\"mCSB_2_container\"]/li"));
		for (WebElement element : elements) {
			String mCSB = element.getText();
			
			if (mCSB.equalsIgnoreCase("NIFTY 100"))
			{
				element.click();
			}
			System.out.println(mCSB);
		}
	}
}

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.