【发布时间】:2015-10-08 12:19:28
【问题描述】:
您好,我正在开发 Selenium Webdriver,我有一个带有下拉菜单的网站,必须选择下拉值,然后单击一个按钮来加载整个页面。页面加载后,必须使用 xpath 从网页中查找文本。我想将下拉文本写入 xlx 文件,并且我想将文本(从 xpath 中找到)写入 xlx。这两个值都是动态的。如何开始,任何代码都可以帮助我。 不使用 maven 和 selenium 我想将数据写入 excel 文件 下面是我要写入excel文件的元素的屏幕截图
我已经写了获取下拉值和 xpath 文本- 想将StockScrip和Pattern写入excel文件
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
import ExcelData.BullishBearishExcelFile;
public class Driver {
public static WebDriver driver;
public static void main(String[] args) {
BullishBearishExcelFile data = new BullishBearishExcelFile();
driver= new FirefoxDriver();
driver.get("http://www.icharts.in");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30000, TimeUnit.SECONDS);
driver.findElement(By.xpath("//a/img[@src='http://www.icharts.in/StockGlance.png']")).click();
//driver.manage().timeouts().implicitlyWait(30000, TimeUnit.SECONDS);
WebDriverWait wait = new WebDriverWait(driver,30);
WebElement webelescripDropDown = driver.findElement(By.id("symbol"));
Select stockName= new Select(webelescripDropDown);
List<WebElement> stocks = stockName.getOptions();
int stockCount = stocks.size();
for(int j=1;j<=stockCount;j++){
webelescripDropDown = driver.findElement(By.id("symbol"));
stockName= new Select(webelescripDropDown);
stockName.selectByIndex(j);
String stockScrip = stockName.getOptions().get(j).getText();
System.out.println(stockScrip+"=stockname clicked");
driver.findElement(By.id("action")).click();
WebElement pattern = driver.findElement(By.xpath("//*[contains(text(),'Short Term (5 days) :')]"));
String bullishPattern = pattern.getText();
System.out.println("Pattern is ="+bullishPattern);
【问题讨论】:
标签: java excel selenium xpath dynamic