我试图减去两个变量的结果,我想在Selenium中回显结果。
我正在使用VS2015作为我的IDE。
//Obtaining pressure For 2100 hours today
driver.FindElement(By.XPath(".//*[@id='hourly']/div[3]/table/tfoot/tr[3]/td[16]")).Click();
//Obtain pressure for 2200 Hours tomorrow
driver.FindElement(By.XPath(".//*[@id='hourly']/div[3]/table/tfoot/tr[3]/td[7]")).Click();
//Subtract the two values above and then 'echo' the result in Selenium
int var2 = 1014;
var2 - var1 = 代码的最后一部分是我需要帮助的地方,请。
有什么想法吗?
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium.Support.UI;
namespace BBC_W_FCast_New_01
{
class Program
{
static void Main(string[] args)
{
//Instantiate Firefox Driver
var driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://www.bbc.co.uk/weather");
//Using the 'Find a Forecast' search field to get the weather in 'Reading, UK'
var user = driver.FindElement(By.Id("locator-form-search"));
//Use "Reading, Reading" to avoid ambiguity. There is a location called Reading in USA
user.SendKeys("Reading, Reading");
//Click on Search button
driver.FindElement(By.Id("locator-form-submit")).Click();
//WebDriver Wait
//Trial Code 1 - WebDriverWait wait = new WebDriverWait(driver, 30);
//Trial Code 2 - wait.until(ExpectedConditions.visibilityOfElementLocated(By.XPath(".//*[@id='hourly']/div[3]/table/tfoot/tr[3]/td[10]")));
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement element = wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("detail-table-view")));
//Click on Table button
driver.FindElement(By.Id("detail-table-view")).Click();
//Obtaining pressure For 2100 hours today
driver.FindElement(By.XPath(".//*[@id='hourly']/div[3]/table/tfoot/tr[3]/td[10]")).Click();
//Obtain pressure for 2100 Hours tomorrow
driver.FindElement(By.XPath(".//*[@id='hourly']/div[3]/table/tfoot/tr[3]/td[16]")).Click();
//Subtract the two values above and then 'echo' the result in Selenium
int val1 = Int32.Parse(driver.FindElement(By.XPath(".//*[@id='hourly']/div[3]/table/tfoot/tr[3]/td[16]")).Text);
int val2 = Int32.Parse(driver.FindElement(By.XPath(".//*[@id='hourly']/div[3]/table/tfoot/tr[3]/td[10]")).Text);
int difference = val1 - val2;
System.Console.WriteLine("Difference is: " + difference);
}
}
internal class WebDriverWait
{
private FirefoxDriver driver;
private TimeSpan timeSpan;
public WebDriverWait(FirefoxDriver driver, TimeSpan timeSpan)
{
this.driver = driver;
this.timeSpan = timeSpan;
}
internal IWebElement Until(object p)
{
throw new NotImplementedException();[![Error - NotImplementedException Was Unhandled][1]][1]错误截图:

发布于 2017-05-18 09:40:34
前两个driver.FindElement只需单击单元格;您可能也希望查询它们的内容:
`var cell16 = driver.FindElement(By.XPath(".//*[@id='hourly']/div[3]/table/tfoot/tr[3]/td[16]")).Text();`在此之后,您将进行减法:
var result = cell16 + cell07;Console.WriteLine(result);
https://sqa.stackexchange.com/questions/27302
复制相似问题