UI TestStack White Get Value from a DataCell - c#

Does anyone know how to get Vlaue from a ""DataCell(DataGridViewTextBoxCell)"?
I need to get a value from DataCell using its "Name" = "Symbol Row 0" or "RuntimeId" = "42 1966418 3 1 0"".
My current code is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TestStack.White;
using TestStack.White.Factory;
using TestStack.White.UIItems;
using TestStack.White.UIItems.Finders;
using TestStack.White.UIItems.WindowItems;
namespace UI_006
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(System.Diagnostics.Process.GetProcessesByName("program1")[0].Id);
Application application = TestStack.White.Application.Attach(System.Diagnostics.Process.GetProcessesByName("program1")[0].Id);
Window Calcwindow = application.GetWindow(SearchCriteria.ByText("toto"), InitializeOption.NoCache);
application.WaitWhileBusy();
}
}
}
My UISpy SceenShot:

Related

Set signal value using .NET from Visual studio in CANoe

how can i change signal value in CANoe from C# in Visual Studio? I don't want to make a test module and run it from CANoe, i just want to run from Visual Studio and signal value to be changed. I get this error when i'm trying to set a signal value:
Vector.CANoe.Runtime.Internal.DBTypeNotFoundException: 'The type SignalName could not be found in the configuration.'
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using Vector.PanelControlPlugin;
using NetworkDB;
using Vector.CANoe.Runtime;
using Vector.CANoe.Runtime.Internal;
using Vector.CANoe.Runtime.ValueEntitiesInternal;
using Vector.PostCompiler;
using Vector.CANoe.Sockets;
using Vector.CANoe.VTS;
using Vector.CANoe.VTSInternal;
using Vector.Diagnostics;
using NetworkDB;
namespace Demo
{
public class Class1// : IPanelControlPluginLibrary
{
[OnChange(typeof(NetworkDB.PAAK_WELCOME_LIGHTS))]
public static void OnSignalLockState()
{
double value = 1;
NetworkDB.PAAK_WELCOME_LIGHTS.Instance.GetValue();
}
static void Main(String[] args)
{
OnSignalLockState();
}
}
}
The assemblies Vector.CANoe.Runtime can only be used in .NET code which is run within CANoe, i.e. in Nodes, Tests, Snippets, etc.
If you want to interact with CANoe from outside you have to use the COM-Interface of CANoe.

Selenium c# find element select element exception

I'm fairly new to c# and writing a simple selenium code which will go onto www.asos.com. I then click on the country on the right hand side by finding the xpath. When I click on the country I want to change the country to 'india' and the currency to 'USD', and then select my preference.
I'm getting exception for driver.FindElement, SelectElement, SelectByValue previously when using java I wasn't getting these exceptions.
Exception I see for driver = The name driver doesn't exist in the current context
SelectElement = the type or namespace name 'SelectElement' could not be found
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
namespace Exercise1
{
class Program
{
static void Main(string[] args)
{
IWebDriver webDriver = new ChromeDriver(#"Path to my chrome driver defined here");
webDriver.Navigate().GoToUrl("www.asos.com");
driver.FindElement(By.XPath("//*[#id="chrome - header"]/header/div[2]/div/ul/li[3]/div/button')]")).Click();
var country = driver.FindElement(By.Id("country"));
var select_country = new SelectElement(country);
select_country = SelectByValue("India");
var currency = driver.FindElement(By.Id("currency"));
var select_currency = new SelectElement(currency);
select_currency = SelectByValue("$ USD");
driver.FindElement(By.XPath("//*[#id="chrome - header"]/header/div[5]/div[2]/div/section/form/div[3]/button")).Click();
}
}
driver.FindElement(By.XPath("//*[#id="chrome - header"]/header/div[5]/div[2]/div/section/form/div[3]/button")).Click();
The erro in quotation marks, try:
driver.FindElement(By.XPath("//*[#id='chrome - header']/header/div[5]/div[2]/div/section/form/div[3]/button")).Click();
Use the value of the option in the html. Also call the select on the select element. For example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
namespace Exercise1
{
class Program
{
static void Main(string[] args)
{
IWebDriver driver= new ChromeDriver(#"Path to my chrome driver defined here");
driver.Navigate().GoToUrl("www.asos.com");
driver.FindElement(By.XPath("//*[#id='chrome - header']/header/div[2]/div/ul/li[3]/div/button')]")).Click();
var country = driver.FindElement(By.Id("country"));
var select_country = new SelectElement(country);
select_country.SelectByValue("IN");
var currency = driver.FindElement(By.Id("currency"));
var select_currency = new SelectElement(currency);
select_currency.SelectByValue("2");
driver.FindElement(By.XPath("//*[#id='chrome - header']/header/div[5]/div[2]/div/section/form/div[3]/button")).Click();
}
}
You may also want to throw in some waits to give the page time to load.

C# PhantomJS Xpath Issues

code:
using HtmlAgilityPack;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using OpenQA.Selenium.PhantomJS;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium;
namespace Scrape
{
class Program
{
static void Main(string[] args)
{
PhantomJSDriver driver = new PhantomJSDriver();
driver.Navigate().GoToUrl("http://www.regmovies.com/theatres/theatre-folder/edwards-west-oaks-mall-stadium-14-rpx-9364");
var nodes = driver.FindElementsByXPath(".//*[#id='content']/div/div/div[2]/div[1]/div/div[2]/div[1]/div/div[1]/h3/a");
foreach(var node in nodes)
{
Console.WriteLine(node.Text);
}
Console.Read();
}
}
}
the xpath is valid because it returns something on firebug
however it doesn't show any text.
whats going on?
however setting the xpath to
var nodes = driver.FindElementsByXPath("//a");
yields the movie names but not the specific xpath. what's going on?
Try waiting for the results to appear before getting the show links:
IWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.ElementIsVisible((By.CssSelector("div.results"))));

Create images from PDF file pages in C#

I want to get images from PDF file pages. I know that a good solution is to use ghostscriptsharp. It has a special method to get a single page or multiple pages.
GeneratePageThumbs(string inputPath, string outputPath, int firstPage, int lastPage, int width, int height)
Here is my complete code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GhostscriptSharp;
namespace GetPages
{
class Program
{
static void Main(string[] args)
{
GhostscriptWrapper.GeneratePageThumbs(#"C:\Users\User\Downloads\English_Medium_Extra_for_WEB-2.pdf",
#"C:\Users\User\Desktop\Test", 1, 3, 130, 130);
}
}
}
But when I use this method I have exception.
ExternalException
Ghostscript conversion error
So i fix this!The problem lies in the fact that 2 parameter should be the name of your image you get as a result, not a path where to save the image!
Here is the code works correctly:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GhostscriptSharp;
namespace GetPages
{
class Program
{
static void Main(string[] args)
{
GhostscriptWrapper.GeneratePageThumbs(#"C:\Users\User\Downloads\English_Medium_Extra_for_WEB-2.pdf",
"Example.png", 1, 3, 130, 130);
}
}
}
Thank you!Question is closed.
replace "Example.png" by "Example%d.png" to get all 3 Pages.

How to get grid items --wpf

I made WPF application named as WpfApplication7.It has several folders. One of them is named as Assign_Rights . I have created a UserControl in this folder and named it as Assignment_Rights. Inside this user control i have created a grid and bind it to data explicitly! Now There is button name as Click New. It shows me that PK(Primary Key-Value) of a selected item from grid.
User n = grid.GetRow(view.FocusedRowHandle) as User;
int abc = n.Primary_Key;
Question: As i wrote code to get PK of Selected item it generated error at
int abc = n.Primary_Key;
by saying
Error 'WpfApplication7.Assign_Rights.User' does not contain a definition for 'Primary_Key' and no extension method 'Primary_Key' accepting a first argument of type 'WpfApplication7.Assign_Rights.User' could be found (are you missing a using directive or an assembly reference?) D:\Backup_WPFAppliacation7\New folder\WpfApplication7\WpfApplication7\Assign_Rights\Assignment_Rights.xaml.cs 59 28 WpfApplication7
How to Solve this Error?
EDIT
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using DevExpress.Xpf.Core;
using DevExpress.Xpf.Grid;
namespace WpfApplication7.Assign_Rights
{
public partial class Assignment_Rights : UserControl
{
int useridd;
nrcsaEntities d = new nrcsaEntities();
public Assignment_Rights()
{
InitializeComponent();
}
private void ToggleButton1_Click_1(object sender, RoutedEventArgs e)
{
if (view.IsRowSelected(view.FocusedRowHandle) == false)
{
DXMessageBox.Show("Please Select any Item From Grid List");
}
else
{
User n = grid.GetRow(view.FocusedRowHandle) as User;
int abc = n.Primary_Key;
var getd = from p in d.Users select p;
MessageBox.Show(view.FocusedRowHandle.ToString());
} . . . .

Categories