none
C# extracting value from webpage RRS feed

  • Question

  • Hello, how can i extract value by xpath in selenium.

    My searching element:

    <td>1.4</td>

    my xpath to this value

    IWebElement target = driver.FindElement(By.XPath("/html/body/table/tbody/tr[2]/td[2]/table[2]/tbody/tr/td/table/tbody/tr/td/table/tbody/tr/td/div[4]/div/table/tbody//td[contains(@style,'text-align: center;')and contains(text(),'?')]/following-sibling::td[1]"));

    I want to extract 1.4  and save as double type, how can I do this?

    Tuesday, November 13, 2018 1:01 PM

Answers

All replies

  • Hi,

    use Double.TryParse(string, out double output) and parse the content of td... If the method returns true, it is an valid double...

    Greetings, Chris

    Tuesday, November 13, 2018 1:26 PM
  • but how can i implement string as Xpath location?
    Tuesday, November 13, 2018 1:41 PM
  • using System;

    using System.Collections.Generic;

    using System.Linq;using System.Text;

    using System.Threading.Tasks;

    using OpenQA.Selenium;

    using OpenQA.Selenium.Firefox;

    using OpenQA.Selenium.Support.UI;

    using System.Collections.ObjectModel;

    namespace FFdriver{

    class Program

    {

    static void Main(string[] args)

    {

    FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(@"C:\...");

    service.FirefoxBinaryPath = @"C:\Program Files\Mozilla Firefox\firefox.exe";

    IWebDriver driver = new FirefoxDriver(service);

    driver.Navigate().GoToUrl("firstpage");

    driver.FindElement(By.Id("user")).SendKeys("123");

    driver.FindElement(By.Id("password")).SendKeys("abc");

    System.Threading.Thread.Sleep(1000);

    driver.FindElement(By.ClassName("btn-login")).SendKeys(Keys.Enter);

    System.Threading.Thread.Sleep(1000);

    IWebElement elem = driver.FindElement(By.ClassName("world_button_active"));

    elem.Click();

    System.Threading.Thread.Sleep(1000);

    driver.Navigate().GoToUrl("secondpage");

    IWebElement asys = driver.FindElement(By.XPath("//td//table//td//a[@class='manager_icon'] [@title=Manager']"));

    asys.Click();

    System.Threading.Thread.Sleep(1000);

    IWebElement target = driver.FindElement(By.XPath("/html/body/table/tbody/tr[2]/td[2]/table[2]/tbody/tr/td/table/tbody/tr/td/table/tbody/tr/td/div[4]/div/table/tbody//td[contains(@style,'text-align: center;')and contains(text(),'?')]/following-sibling::td[1]"));

    */ target points to this line

    <td>1.4</td>

    and i want to extract this value for example as X

    So our X = 1.4

    */

    Console.WriteLine("value: ", X);

    Console.Read();

    }

    }

    }


    On Console i should see

    value: 1.4




    • Edited by Emsen Tuesday, November 13, 2018 2:02 PM
    Tuesday, November 13, 2018 1:54 PM
  • I figured it out!
    • Marked as answer by Emsen Tuesday, November 13, 2018 3:32 PM
    Tuesday, November 13, 2018 3:32 PM