private void button2_Click(object sender, EventArgs e)
{
//read in file data and calculate record number
string csv = File.ReadAllText("File-Path");
int testing = 1;
XDocument doc = ConvertCsvToXml(csv, new[] { "\t" });
//create array of record number
WebService.Function[] xxx = new WebService.Function[1];
recordAmount = 0;
Hi there for some reason in the above code the ConvertCsvToXml line is bringing back an exception saying it does not exist, and the intelisense brings up nothing after typing XDocument.
What can I do to resolve this? There are no errors in my code other than this!
Thanks for your time.
You'll have to define the ConvertCsvToXml method in the same class as the button2_Click method.
Related
Hello everyone am working on a project for work and I just started using C# and selenium. I need to pick a value in this case a name from a list I provide inside a textbox for example jack david john eren kevin they dont need to be a specific number of names and I need them to be inserted into a TextBox from which the first name will be picked and sent to a webpages text field I have tried to use a random function but that did not work i need it to pick in order from first to last Jack->SENDKEYS and then after its done filling up a request it would go to the following David->SENDKEYS and same scenario but its really important to not just send the one after the other but after the completion of the whole webpage i was using a demo google form for this so i could figure out how to do this but i got stuck here this is my code
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
} //names
private void TextBox_TextChanged_1(object sender, TextChangedEventArgs e)
{
}
//size
private void size_TextChanged(object sender, TextChangedEventArgs e)
{
//string sizes = size.Text;
}
//emails
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
string emails = question1.Text;
string fnames = name.Text;
string region = country.Text;
string sizes = size.Text;
ChromeDriver driver = new ChromeDriver(#"C:\webdrivers");
ChromeDriver drv; Thread th;
string url = "https://docs.google.com/forms/d/e/1FAIpQLSeI8_vYyaJgM7SJM4Y9AWfLq-tglWZh6yt7bEXEOJr_L-hV1A/viewform";
HashSet<string> names = new HashSet<string>();
names.Add("name1", names.Add("name2"));
foreach (string name in names) ;
driver.Navigate().GoToUrl(url);
driver.FindElement(By.ClassName("quantumWizTextinputPaperinputInput")).SendKeys(emails);
driver.FindElement(By.ClassName("quantumWizTextinputPapertextareaInput")).SendKeys(fnames);
driver.FindElement(By.ClassName("quantumWizTextinputSimpleinputInput")).SendKeys(region);
driver.FindElement(By.ClassName("quantumWizTextinputSimpleinputInput")).SendKeys(sizes);
}
}
` and it need to be connected to the textbox so that i could just place the textbox name into send keys command thank you!
Not 100% sure what you're after here, but would this help you get started?
var names = new HashSet<string>()
{
"jack",
"david",
"john",
"erin",
"kevin"
};
var namesElement = driver.FindElement(By.ClassName("quantumWizTextinputPapertextareaInput"));
foreach (string name in names)
{
namesElement.SendKeys(name);
}
Am trying to solve this issue I have for work I saw that selenium is quite useful and I wanted to save time and energy doing the same task everyday so I tried making a really basic way to solve the current issue I have with C# and Selenium I need to do the following.
I'm trying to figure out how I could connect a textbox (multiple text input) to then randomly pick one and send it to a webpage. This is my code so far:
namespace emails
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
//textbox input
string quest = question1.Text;
var random = new Random();
var names = new List<string> { question1.Text};
int index = random.Next(names.Count);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
ChromeDriver driver = new ChromeDriver(#"C:\webdrivers");
ChromeDriver drv; Thread th;
string url = "https://accounts.google.com/signin/v2/identifier?continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&service=mail&sacu=1&rip=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin";
driver.Navigate().GoToUrl(url);
driver.FindElement(By.ClassName("whsOnd")).SendKeys(question1.Text); Thread.Sleep(2000);
}
}
}
I tried this but as expected this would just send the whole textbox input.
Assumimg question1 contains several lines and you want to pick 1 line, ie question1 is:
SomeLineWhichIsaName
AnotherLineAnotherName
SomeMoreName
You want to split question1 on linebreaks, which gives you a list of lines (3 in this case, they seem to be names). Than your random function works.
var names = question1.Text.Split("\r\n");
int index = random.Next(names.Count);
string randomName = names[index];
driver.FindElement(By.ClassName("whsOnd")).SendKeys(randomName)
\r\n or \r or \n => just figure out what works
I'm writing a FlashCard app in Windows Form.
Right now I'm trying to do is read word from string array and pass it to label. Then asking user to write the translation of this word. And finally pass the result to label box.
Here is my code:
public partial class EnglishPolishScreen : Form
{
//English words array
string[] words = new string[] { "word1", "word2", "word3", "word4" };
// meanings words array
string[] wordB = new string[] { "slowo1", "slowo2", "slowo3", "slowo4" };
int element = 0;
Thread thread;
public EnglishPolishScreen()
{
InitializeComponent();
}
private void CloseAppEvent(object sender, FormClosingEventArgs e)
{
Application.Exit();
}
private void button1_Click(object sender, EventArgs e)
{
thread = new Thread(Threadd);
thread.Start();
}
private void Threadd()
{
englishWord.Text = words[element];
counterLabel.Text = element + 1 + " of " + words.Length;
if (answerBox.Text.Equals(wordB[element]))
{
resultLabel.Text = "Good";
element++;
}
else
resultLabel.Text = "Bad";
if (element == words.Length)
{
element = 0;
}
}
private void EnglishPolishScreen_Load(object sender, EventArgs e)
{
englishWord.Text = words[element];
}
Edited
Guys, Why I have to click two times in button to see next item from array? And why I can see "bad" answer straight after I click button? The "Good" answer shows up after second click.
Edited v2.xD
Sorted. Anyway is it good way to write code like this? If not how It could look better? Thanks
Regards
On button click, it is going through the whole for loop, i.e. the entire list of meanings, you would have to break the for loop as soon as a right match is found. So just use break; after resoultLabel.Text = "Good answer!";. Also as pointed out by #Neil, it is not good to use UI in a separate background thread.
By the way, I am not able to wrap my head around the logic of chances. For giving chances you would have to declare a global variable which would get added/subtracted when the a bad answer is found after Iterating through whole for loop, disallowing any further trial for the word.
On our job database we have a http address that ends with "projects/Project/Entry/5893" The 5893 is the job number that will change job to job.
I have a timer set to go through each number till it gets this page End Page. So on the End Page HtmlElement does not exist so it gives me the System.NullReferenceException and there for i know the last used job number. But the Problem is that the Exception does not pop up. Does anyone know an easier way to do this. Sorry for not showing the complete webpage address it has sensitive information.
private int a = -1;
private string NJNumber = File.ReadAllText(#"...\CurrentJobNumber.txt");
//The Last Confirmed Number by me and where to start searching from.
private void NewJob_Click(object sender, EventArgs e)
{
HtmlDocument doc = nwJob.Document;
a = Convert.ToInt32(NJNumber);
JobNumberTimer.Start();
}
private void JobNumberTimer_Tick(object sender, EventArgs e)
{
HtmlDocument doc = nwJob.Document;
string aJN = a.ToString();
try
{
nwJob.Navigate("..../projects/Project/Entry/" + aJN);
HtmlElement njname = doc.GetElementById("Name");
a += 1;
}
catch(System.NullReferenceException)
{ lblJobNumber.Text = a.ToString();
JobNumberTimer.Stop();
}
}
I don't think that HtmlDocument.GetElementById will throw a NullReferenceException.
You could try and check the body of the the html doc for something on the error page.
doc.Body.InnerText.Contains("somthing to search for")
I can't find a solution for this problem:
I write a program, which reads all file in a directory and puts them in a listbox.
When a user select a file from a listbox, the program reads the selected file and prints out some info...
The problem is that after the firs selection my program "stop working". He don't crash, but when I try to select another file he do nothing.
I figured out, that the problem is in:
private String porocilo(String s)
{
file = "/path to file/";
TextReader tr = new StreamReader(file); //<- problem here
//...
tr.close();
return someinfo;
}
//..
//Call function:
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
label1.Text = porocilo(listBox1.SelectedItems[0].ToString());
}
After removing that (problem) line the program normally select files, but without this I can't read files and my program don't do anything.
Can someone tell me where I'm wrong?
Br, Wolfy
If the code you posted is really the code you are using (plus the missing semicolon), then the reason you are not seeing anything happening is because your code keeps opening and reading the same file, not the file the user selected. You are setting file to a constant path/filename and read from that, and you are not making use of the s parameter.
It looks like you have a hard-coded path in your porocilo method. That is, new StreamReader is taking as it's argument, file, not s.
So it will only ever open, one file, not the file you selected.
private String porocilo(String s)
{
//file = "/path to/file" // not sure what this is...???
TextReader tr = new StreamReader(s); //<- fix here
//...
tr.close();
return someinfo;
}
In your List box Selected index change method you need to assign the selected value as shown below
//Call function:
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
label1.Text = porocilo(listBox1.SelectedItem.Text);
}
Also check your "porocilo" function it uses the parameter corectly