I have a problem, I want to write a code in selenium C# (or another way) that getting dynamic value from a webpage (like clock) and display in my APP, The value of the variable within the webpage changes frequently and I want to display this value in my APP,I use a string variable to display value.
with below code:
string realTime= driver.FindElement(By.XPath("//span[#class='RealServerTime']")).Text;
but its a static text, and it does not display changes to the value of the variable, I don't really know that I can use selenium for this or not!? can everyone help me? thanks a lot
This is my code:
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Surena
{
class Timing
{
IWebDriver driver = new ChromeDriver();
public void clock(string textSend)
{
driver.Url = "http://www.tsetmc.com/Loader.aspx?ParTree=15";
string realTime= driver.FindElement(By.XPath("//span[#class='RealServerTime']")).Text;
}
}
}
You could use WebDriverWait class to wait until given change and set condition that Text or other value change.
https://www.selenium.dev/selenium/docs/api/dotnet/html/T_OpenQA_Selenium_Support_UI_WebDriverWait.htm
Related
I am using R.NET to perform computation in my C# application and
now I'd like to display the results in a Winform.
Anyone could advise on how to embed a R plot in a winform using R.NET ?
I found the below post which seems outdated as I can't find any reference nor Nuget package for the RNETGraph namespace that they use. The link referenced in the post have also been archived.
display multiple R Embedded Graph in multiple panel winform c#
And I would like to avoid the ugly solution of saving the image and then loading it in a PictureBox as I need to change the plot dynamically according to user input.
Thanks
You can use Dieter Menne's RGraphHooks to display R's plot output in a graphical WinForms element (e.g. a Windows.Forms.Panel). RGraphHooks has a dependency to Dino Esposito's Win32 hooks library.
Usage of RGraphHooks is quite simple. See this blog post by Peter Dai Dinh for a small demo program.
What you basically do is, you attach an RGrapHook to a specific control in your WinForms GUI and then wrap your engine.Evaluate("plot(...)") in this hook:
RGraphAppHook cbt = new RGraphAppHook { GraphControl = panelForPlot };
cbt.Install();
engine.Evaluate("plot(rnorm(100))");
cbt.Uninstall();
I never got hold of R.NET - documentation just wasn't very clear.
There is another option, however. You can use the command line to transfer arguments from your C# application to your R.Script.
For example:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string strCmdText;
strCmdText = "Rscript.exe [directory here]\\script.R 10 arg2"; //what comes after script.R are the arguments you are passing.
System.Diagnostics.Process.Start("CMD.exe", strCmdText);
}
}
}
Then, it is very easy to retrieve the arguments in the R Script. Just use:
args <- commandArgs(trailingOnly = TRUE)
var1 <- args[1] #Argument 1
var2 <- args[2] #Argument 2
Addendum: Please note, you should have your RScript.exe in the environment variables in order to get the above to work.
I am currently working on a small program, that loads an image file into the Console and print it out as an asci image. I am using the ".Net Console application framework 4". My Problem is, that I do not know how to create a Bitmap. After browsing for a while, I found many answers to my question, that suggested the "System.Drawing.Bitmap" class. When I try to refer to this class, visual studio does not even know System.Drawing.Bitmap. I have a class "AsciArt" which should convert the picture in the method ConvertToAsci. Does anybody know what my mistake is?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing.Bitmap;
namespace consoleGrafix
{
class AsciArt
{
private string ImgLink;
public AsciArt(string imageLocation)
{
this.ImgLink = imageLocation;
}
public void ConvertToAsci(string saveLocation)
{
var bm = Bitmap(saveLocation);
}
}
}
The solution was to set up my class by inheriting from image class. Also, in the ConvertTo Asci method, there was a "new". https://learn.microsoft.com/en-us/dotnet/api/system.drawing.bitmap?view=netframework-4.0 . This really helped. Thank you!
I'm trying to use the Process class but it gives me this compiler error every time I do
The name 'Process' does not exist in the current context
I've already added using System.Diagnostics; at the top of my code but I still get this error. Autocomplete wont even recognize the class.
Hear is the code. I've only included the Main method because the rest of the code has nothing to do with the error.
using System;
using System.Reflection;
using System.Collections.Generic;
using System.IO;
using System.Diagnostics;
public class MainClass
{
static void Main()
{
AIRuntime adam = new AIRuntime("Adam", false);
adam.AIUpdate();
Process.Start(adam.directory); //adam.directory is just a string
}
}
My IDE is Xamarin Studio if it matters.
After web searching and attempts, I found the problem.
To fix this, I manually add a reference to System in my project options instead of just typing using System;. I also need to keep using System.Diagnostics; at the top. It's all in the picture below
Thanks guys for trying to help
I've jjust started off with Selenium Webdriver and I've hit an issuee straight away involving the buttons I'm trying to select/click all have no IDs and share the same class.
So I'm wondering how I select these by the unique text they contain.
I'm thinking possibly with css selector maybe, but I'm unsure how to also tell it to look for specific text to select the element.
All I currently have is:
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium.Internal;
namespace SeleniumTest1.Methods
{
public class HomePage
{
private readonly IWebDriver _browser;
public HomePage(IWebDriver browser)
{
_browser = browser;
}
public IWebElement SearchBox()
{
return _browser.FindElement(By.Id("searchBox"));
}
public void ImageButton()
{
_browser.FindElement(By.CssSelector("a")).Click();
}
}
}
Very basic so far.
Where I have the CssSelector I'm not sure if theres anyway to say select "a" containing text "xyz".
I've tried search for ways but can't find anything, though I feel this must be an issue which has been raised before, thanks.
Fairly easy if you use xpath.
if it has unique text your xpath should look like something like this
//button[.='xyz']
So, here "." points to the parent in HTML hierarchy and just look for text
You can find the link by the visible text.
IWebElement XyzLink= _browser.FindElement(By.LinkText("xyz"));
Also you can locate the link by partial link text as follows,
IWebElement XyzPartialLink= _browser.FindElement(By.PartialLinkText("XYZ"));
For example this will locate a link element which contains 'XYZ' in its text.
I'm bit new at this so excuse me if my question is a bit novice. I'm designing a Windows form application to basically replace an old excel spreadsheet then email system(not that its much of a system). After the forms are filled out the answers are saved in terms of public variables, which is fine since it's a small program. Im having trouble referencing my variable from another windows form. Basically, I would like to have the filled out form close and a new "review" window pop up. I'm just using labels that will be show what the value of the variable is. If it was in the same class it wouldn't be a problem but im using two different forms that are partial classes of the same namespace. A bit of code:
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace OPS_PictureLoader
{
public partial class Points_Screen : Form
{
public int DevJobStandardsTotal = 0;
And the label I would like to show a "0"(or whatever the program has added to it)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace OPS_PictureLoader
{
public partial class Review : Form
{
public Review()
{
InitializeComponent();
label14.Text = DevJobStandardsTotal;
Again, thanks and feel free to tell me Im totally wrong :D
You need to pass the instance of the first form to the second form's constructor:
public Review(Points_Screen owner)
{
InitializeComponent();
label14.Text = owner.DevJobStandardsTotal;