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"))));
Related
I am trying to open the Register page from my account.
The UI developer used the bootstrap code. Bootstrap developers have added the JS function on click.
and when I run this code then show error "OpenQA.Selenium.ElementClickInterceptedException has been thrown
element click intercepted: Element ... is not clickable at point (984, 50). Other element would receive the click: ...
(Session info: chrome=77.0.3865.120)"
Attached Screenshot link:
https://monosnap.com/file/1z5PYCFBHfcXtkWJWVMi4SeejUXXOf
https://monosnap.com/file/hdq3194312RCnvc6GdQXLLVqtoezNJ
This my code
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
namespace XTSeleniumtest
{
class MainClass
{
public static void Main(string[] args)
{
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("http://freshpicksdev.isrv.tech/");
driver.FindElement(By.CssSelector("div.modal-header .close")).Click();
driver.FindElement(By.XPath("//a[#id='navbarDropdown']/u")).Click();
}
}
}
**`
> strong text
`**
You can wait until the element is visible.
driver.FindElement(By.XPath("//a[#id='navbarDropdown']/u"));
If still the issue exists please post the DOM structure of your web page,it may be related to interacting with a wrong element.
Try the below code. You would need to add reference for "SeleniumExtras.WaitHelpers" from nuget
class MainClass
{
public static void Main(string[] args)
{
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("http://freshpicksdev.isrv.tech/");
driver.FindElement(By.CssSelector("div.modal-header .close")).Click();
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.IgnoreExceptionTypes(typeof(NoSuchElementException));
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.XPath("//u[contains(text(),'My Account')]")));
driver.FindElement(By.XPath("//u[contains(text(),'My Account')]")).Click();
driver.FindElement(By.XPath("//a[text()='Register']")).Click();
}
}
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.
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:
So, I have this simple code
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.PhantomJS;
class Program
{
static void Main(string[] args)
{
IWebDriver driver = new PhantomJSDriver();
driver.Navigate().GoToUrl("http://someurl");
try
{
IWebElement search = driver.FindElement(By.XPath("//*[#id=comboInput']"));
search.SendKeys(".");
IWebElement searchtext = driver.FindElement(By.XPath("//*[#id='itext']"));
searchtext.SendKeys(".");
IWebElement searchsend = driver.FindElement(By.XPath("//*[#id='buttonArea']/center/table/tbody/tr/td[2]/a")).Click();
Console.WriteLine("Did it");
}
catch
{
Console.WriteLine("Nope");
}
}
}
I have no idea what's wrong with this code. The error is :
cannot implicitly convert type 'void' to 'OpenQA.Selenium.Iwebelement'
And the problem is with IWebDriver driver
Note : If this is a stupid question and I'm missing some kind of obvious fix, let me know. But I honestly can't figure out what's wrong with this.
The problem is with this line:
IWebElement searchsend = driver.FindElement(By.XPath("//*[#id='buttonArea']/center/table/tbody/tr/td[2]/a")).Click();
You're assigning the result to searchsend but Click 'returns' void.
I'm new to C# and I'm new to Speech.Recognition.
I searched very long for tutorials but didn't find that much, I'm even not quiet sure whether I included everything correctly.
I downloaded:
SDK
Runtime
Languages
I'm programming local, I have Windows XP, .net framework 3.5.
Now I just want to get started with some simple lines of code, like to say "hello world" or say one or two words as input.
I tried following, and of course it doesn't work :>
error:
"The Typ- or Namespacename "SpeechSynthesizer" couldn't be found (Is a Using-Direktive or a Assemblyverweis missing?)"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech.Recognition;
using System.Speech.Synthesis;
namespace System.Speech.Recognition { }
namespace System.Speech.AudioFormat {}
namespace System.Speech.Recognition.SrgsGrammar{}
namespace System.Speech.Synthesis { }
namespace System.Speech.Synthesis.TtsEngine { }
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SpeechSynthesizer foo = new SpeechSynthesizer();
foo.Speak("Test");
}
}
}
edit:
hello,
i tried you code,but
using SpeechLib;
couldn't be found :>
well now i wrote:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.SpeechLib;
namespace System.SpeechLib { }
namespace System.Speech.Recognition { }
namespace System.Speech.AudioFormat {}
namespace System.Speech.Recognition.SrgsGrammar{}
namespace System.Speech.Synthesis { }
namespace System.Speech.Synthesis.TtsEngine { }
but I get an error with:
numericUpDown1,SpVoice,SpeechVoiceSpeakFlags,textBox1 and Timeout
Project + Add Reference, .NET tab, select "System.Speech".
A project template pre-selects several .NET assemblies. But only common ones, like System.dll, System.Core.dll, etcetera. You have to add the 'unusual' ones yourself.
you can try this:
get Interop.SpeechLib.dll
using SpeechLib;
private void ReadText(string readText)
{
int iCounter = 0;
while (Convert.ToInt32(numericUpDown1.Value) > iCounter)
{
SpVoice spVoice = new SpVoice();
spVoice.Speak(textBox1.Text, SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak);
spVoice.WaitUntilDone(Timeout.Infinite);
iCounter = iCounter + 1;
}
}