In a short time I will begin automating a web site that has ext.net controls in it. I actually tried to automate a simple scenario as a sample from "http://examples.ext.net/" site. Click > Form > Field Note > Overview but I couldn't manage to write text to simple note textbox. Could you provide a code sample that is working? I tried to get by XPath and other means that can be used with by class. If I try to get all the inputs I get them but SendKeys or Click methods don't work. I get Element Not Visible exception. Could you provide a code sample that is working?
IWebElement htmlElement = driver.FindElement(By.TagName("html"));
IList<IWebElement> inputList = htmlElement.FindElements(By.TagName("input"));
(I get all the inputs but I can't write note...)
I did the following in Java and you can easily convert it to C# if you choose to.
I use a utility method to first properly query for the correct element:
class Utils
{
public WebElement query(String componentQuery) {
String query = componentQuery;
String cmd = String.format("Ext.ComponentQuery.query('%s')[0]", query);
String js = "return " + cmd + ".id;";
String id = (String) ((JavascriptExecutor) driver).executeScript(js);
return driver.findElement(By.id(id));
}
}
Then you can get your component here:
WebElement componentElement=Utils.query("Your-ExtJS-Query-for-the-component-goes-here"+".inputEl");
componentElement.sendKeys(valuesToSet)
Related
I need to get the WebElement name(Userdefine name) for reporting Purpose. Performing Click operation on AddMainConcernLink : If The element is Clicked/not .I need to report "AddMainConcernLink" is Clicked/not found
[FindsBy(How = How.CssSelector, Using = "[data-test-id='ECNMainConcernsLink']")]
private IWebElement AddMainConcernLink;
public void Click(IWebElement element)
{
element.Click();
Console.WriteLine("Perfomed click operation on element : " + element);
}
I want to Print Perfomed click operation on Element: AddMainConcernLink.
I simply pass a descriptive parameter along with the web element to my helper routines. For example, in a calculator Android app, I have the following:
public void clickDegreeRadsToggle() {
helper.click(degreeRadsToggle, "Degree/Rads Toggle");
}
And the helper.click method then logs using the passed description.
I have seen several posts on various forms varying in times from 2006 to now about how to add hyperlinks to RichTextBox, but they all seem overly complex for what I want. I am creating a desktop chat client, and I receive input as strings, now among these strings may be some urls, I need those urls to be clickable. Which from what I gather means they need to be HyperLink objects.
Navigating through the RichTextBox and replacing the urls with HyperLinks seems to be no small feat. Does anyone have a relatively simple solution for this?
In my web client it's a simple one liner
value = value.replace(/(http:\/\/[^\s]+)/gi, '$1');
Never thought I'd see the day where C# actually makes it harder.
If you want to do an equivalent of value.replace(/(http:\/\/[^\s]+)/gi, '$1') in WPF:
<RichTextBox x:Name="MyRichTextBox" IsDocumentEnabled="True" IsReadOnly="True" />
And the code that converts the string is the following:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var htmlText = "Google's website is http://www.google.com";
MyRichTextBox.Document = ConvertToFlowDocument(htmlText);
}
private FlowDocument ConvertToFlowDocument(string text)
{
var flowDocument = new FlowDocument();
var regex = new Regex(#"(http:\/\/[^\s]+)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
var matches = regex.Matches(text).Cast<Match>().Select(m => m.Value).ToList();
var paragraph = new Paragraph();
flowDocument.Blocks.Add(paragraph);
foreach (var segment in regex.Split(text))
{
if (matches.Contains(segment))
{
var hyperlink = new Hyperlink(new Run(segment))
{
NavigateUri = new Uri(segment),
};
hyperlink.RequestNavigate += (sender, args) => Process.Start(segment);
paragraph.Inlines.Add(hyperlink);
}
else
{
paragraph.Inlines.Add(new Run(segment));
}
}
return flowDocument;
}
}
It uses the same regular expression you provided, which is lacking if you properly want to recognize URLs with a regular expression. This one doesn't recognize https ones and the last dot in the following sentence would be a part of the URL: "This is a URL: http://www.google.com/."
What the code does is to split the text based on the regular expression, iterate it and adds the correct elements to the FlowDocument constructed on the fly.
Clicking the Hyperlink should open your default browser.
Result:
That said, this is only good for read only usage of the RichTextBox (as indicated by the question in the comment).
I am writing the test code using java selenium web driver,
I want to search for "Honey rose varghese" and when the result is available, from this result I want to click the Filmography link available on the result page.
public class ByPartialLink {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver",System.getProperty("user.dir")+"\\chromedriver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.co.in");
WebElement searchbox = driver.findElement(By.id("lst-ib"));
searchbox.sendKeys("Honey rose varghese");
searchbox.submit();
Thread.sleep(3000);
List<WebElement> search = driver.findElements(By.partialLinkText("Filmography"));
System.out.println(search.size());
}
}
This worked for me and returned 1. I just searched for the full link text instead of partial. Using a Thread.sleep() isn't a best practice. Try the WebDriverWait below for better, more consistent results.
driver.get("http://www.google.co.in");
WebElement searchbox = driver.findElement(By.id("lst-ib"));
searchbox.sendKeys("Honey rose varghese");
searchbox.submit();
WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("resultStats")));
// Thread.sleep(3000);
List<WebElement> search = driver.findElements(By.linkText("Filmography"));
System.out.println(search.size());
EDIT 1: after feedback
If you want to click the first Filmography link, there are a couple ways to do this...
1) Maybe you want to count the number of links to make sure there's only one, etc. You could still use the code above but click the first element.
List<WebElement> search = driver.findElements(By.linkText("Filmography"));
search.get(0).click();
2) If you always want to click the first link or are confident that there will ever only be one link you can just use .findElement() to return only the first element and click it.
WebElement search = driver.findElement(By.linkText("Filmography"));
search.click();
or a one-liner...
driver.findElement(By.linkText("Filmography")).click();
Best practice in a case like this (where there might be none or more than one search result) would be to return the collection and make sure there is at least one.
List<WebElement> search = driver.findElements(By.linkText("Filmography"));
if (!search.isEmpty())
{
search.get(0).click();
}
I am using DevXpress 14.
I want to use only one form name "FrmViewer" which contain DocumentVier to load any report I want.
This is the code, the datasource is not null (debugged), but the message is "The document contain no page". I think I missed some method of the documentViewer to start print
public FrmViewer(PhieuNhap pn)
{
InitializeComponent();
RptPhieuNhap rpt = new RptPhieuNhap();
rpt.DataSource = pn.ChiTietPhieuNhap;
rpt.nhacungcap.Value = pn.NhaCungCap.TenCC;
rpt.sophieu.Value = pn.SoPhieu;
documentViewer1.PrintingSystem = rpt.PrintingSystem;
}
You most likely need to call rpt.CreateDocument();
See here for more details:
https://www.devexpress.com/Support/Center/Question/Details/Q528191
I designed a report form and map fields with columns of tables from dataset. Now I need to set condition, so I used FilterString. Inside report form DetailReport, I wrote code like this:
DetailReport.FilterString = "[InvoiceNumber] = " + temp;
Now I need this same code (FilterString) for whole form that is top left of form Report Task some properties are available in that Data Source there we add dataset, Data Member, Data Adapter then FilterString is available.
Now I am able to add FilterString in Designer but I need to add FilterString in code ??
I Tried this one but not working
FilterString= "[InvoiceNumber] = " + temp"
I seggest you set the report FilterString property when you call for your XtraReport (for example : when you click on the print button of your form). Here is an code example :
private void simpleButton1_Click(object sender, EventArgs e) {
// Create a report instance.
XtraReport1 report = new XtraReport1();
// Some code like setting the report datasource
// Specify the report's filter string.
report.FilterString = "[InvoiceNumber] = myValue";
// Show the report's print preview.
pt.ShowPreviewDialog();
}
This code was taken from the DevExpress online documentation article : XtraReportBase.FilterString Property
Once you set the filter for the report, in the for you need to have it do:
public string p = "";
....
using (XtraReport_yourreport x = new XtraReport_yourreport ())
{
p = x.FilterString;
}