如何使用selenium webdriver从canvas获取工具提示文本

时间:2017-08-03 16:41:12

标签: selenium canvas webdriver tooltip

如果有人帮我解决了以下问题,那将是一个很大的帮助。

这里我试图在第一行的第一个灰色框上显示与鼠标悬停关联的tooltip文本。但仍然没有运气。如有更多细节,请通知我。

网络链接: - https://www.redbus.in/search?fromCityName=Bangalore&fromCityId=122&toCityName=Goa&toCityId=210&onward=25-Aug-2017&opId=0&busType=Any#

public class RedBus {

    WebDriver driver;
    WebDriverWait wait;

    @BeforeTest
    public void run() {

        System.setProperty("webdriver.gecko.driver", "C:\\geckodriver.exe");
        String baseUrl="https://www.redbus.in/";
        driver=new FirefoxDriver();
        driver.get(baseUrl);
        wait=new WebDriverWait(driver,5);
    }

    @Test
    public void testFunctionality() {

        try { 
            driver.findElement(By.id("src")).clear();
            driver.findElement(By.id("src")).sendKeys("Bangalore");
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("li.selected")));
            driver.findElement(By.cssSelector("li.selected")).click();
            driver.findElement(By.id("dest")).clear();
            driver.findElement(By.id("dest")).sendKeys("Goa");
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("li.selected")));
            driver.findElement(By.cssSelector("li.selected")).click();
            driver.findElement(By.xpath("//div[@id='rb-calendar_onward_cal']/table/tbody/tr[4]/td[3]")).click();
            driver.findElement(By.id("search_btn")).click();

            String Busname=driver.findElement(By.xpath("//ul//li[2]//div[@class='service-name']")).getText();
            String departTime=driver.findElement(By.xpath("//ul//li[2]//div[@class='fl depart']")).getText();
            String arrivalTime=driver.findElement(By.xpath("//ul//li[2]//div[@class='fl arrive']")).getText();
            String totalSeats=driver.findElement(By.xpath("//ul//li[2]//div[@class='fl seats']//span[@class='tot-seats']")).getText();
            String fare=driver.findElement(By.xpath("//ul//li[2]//div[@class='fare']")).getText();

           System.out.println(Busname+" "+departTime+" "+arrivalTime+" "+totalSeats+" "+fare );

           driver.findElement(By.xpath("//ul//li[2]//button[@class='view-seats button to-be-hidden']")).click();

           Actions builder=new Actions(driver);

           wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='upper-canvas canvas-wrapper']//canvas")));

           WebElement Upper=driver.findElement(By.xpath("//div[@class='upper-canvas canvas-wrapper']//canvas"));

           Action movetoUpper=builder.moveToElement(Upper).build(); 

           movetoUpper.perform();

           System.out.println("tooltip text"+  Upper.getAttribute("title"));
           System.out.println("SEAT NO:"+  Upper.getText());

        }
        catch(NoSuchElementException ex) {
        }
    }

}

0 个答案:

没有答案