Win Phone 8 WP8 Creating Dynamic Controls at runtime - windows-phone-8

I need to be able to create dynamic controls at runtime - textblocks, buttons to be specific. I have tried this:
dim b as button = new button
b.content="test"
The code does not error but also does not produce a button either. Simple I know but for Wp8 it's quite difficult for me.
Thanks

You still need to add the button to your page. Try this:
Xaml
<ContentControl x:Name="container">
</ContentControl>
Code
Dim b as New Button With { .Content = "test"}
container.Content = b

Related

vb.net selenium select element from dropdown

I don't know much about selenium. I'm trying to select an element from a dropdown to click on it, but vb.net doesn't find this element. or it finds another element that has the same class name.
It is the following dropdown menu on aliexpress.
And this is the code I have written so far....
Dim chromeDService = ChromeDriverService.CreateDefaultService() 'hides command prompt
chromeDService.HideCommandPromptWindow = True
Dim opt As New ChromeOptions()
opt.AddArguments("headless") 'prevents driver from opening a new window
Dim driver As IWebDriver = New ChromeDriver(chromeDService, opt)
driver.Navigate.GoToUrl(URL_AS_STRING) 'the URL as String
driver.Manage.Timeouts().ImplicitWait = TimeSpan.FromSeconds(2)
If driver.FindElement(By.ClassName("switcher-info")).FindElement(By.ClassName("currency")).Text = "USD" Then
Console.WriteLine("changing currency...")
'driver.FindElement(By.LinkText("EUR")).Click()
driver.FindElement(By.ClassName("switcher-info")).Click()
driver.Manage.Timeouts().ImplicitWait = TimeSpan.FromSeconds(1)
Dim element As IWebElement = driver.FindElement(By.ClassName("switcher-common")).FindElement(By.ClassName("switcher-currency-c")).FindElement(By.ClassName("select-item"))
Console.WriteLine(element.GetAttribute("innerText"))
End If
My question now is, how can I select and click on the element with the currency?
I intend to click on it so that it selects another currency.
Of course I could also make everything less complicated and include an exchange API. But the real rates do not match with the prices
You can do it simply by clicking the corresponding elements one by one exactly what the real user does via the GUI.
I see Selenium in VBA doesn't have explicit waits, so only the implicitly wait can be used as you already defined it driver.Manage.Timeouts().ImplicitWait = TimeSpan.FromSeconds(2) and since it was defined we do not need to define it anymore until we want to define it for some other value.
This is what I wrote.
I hope this should work:
If driver.findElementByXPath("//a[#id='switcher-info']//span[#class='currency']").Text = "USD" Then
Console.WriteLine("changing currency...")
driver.findElementByXPath("//span[#class='currency']").Click()
driver.findElementByCssSelector(".switcher-currency .select-item").Click()
driver.findElementByXPath("//a[#data-currency='EUR']").Click()
driver.findElementByXPath("//button[#data-role="save"]").Click()
In case there are pop-ups appearing on the aliexpress home screen disturbing the above code run try do the following:
If driver.FindElementsByXPath("//div[contains(text(),'Don')]").Count Then
driver.FindElementsByXPath("//div[contains(text(),'Don')]").Click()
If driver.FindElementsByXPath("//img[#class='btn-close']").Count Then
driver.FindElementsByXPath("//img[#class='btn-close']").Click()
If driver.FindElementsByXPath("//img[#class='close-btn']").Count Then
driver.FindElementsByXPath("//img[#class='close-btn']").Click()
And only after that run the code above so that the whole code will be something like this:
If driver.FindElementsByXPath("//div[contains(text(),'Don')]").Count Then
driver.FindElementsByXPath("//div[contains(text(),'Don')]").Click()
If driver.FindElementsByXPath("//img[#class='btn-close']").Count Then
driver.FindElementsByXPath("//img[#class='btn-close']").Click()
If driver.FindElementsByXPath("//img[#class='close-btn']").Count Then
driver.FindElementsByXPath("//img[#class='close-btn']").Click()
If driver.findElementByXPath("//a[#id='switcher-info']//span[#class='currency']").Text = "USD" Then
Console.WriteLine("changing currency...")
driver.findElementByXPath("//span[#class='currency']").Click()
driver.findElementByCssSelector(".switcher-currency .select-item").Click()
driver.findElementByXPath("//a[#data-currency='EUR']").Click()
driver.findElementByXPath("//button[#data-role="save"]").Click()
You need to close all the popups before interacting with any element on the page. Try this:-
driver.findElementByXPath(".//div[contains(text(),'notifications')]//following::img").Click()
driver.findElementByXPath(".//img[#class='btn-close']").Click()
driver.findElementByXPath(".//a[#id='switcher-info']").Click()
driver.findElementByXPath(".//div[#data-role='switch-currency']").Click()
driver.findElementByXPath(".//li/a[#data-currency='EUR']").Click()
I think, that the ClassName-Selector ist not the right one.
It is not a real dropdown like <select> but a dropdown-menue of links.
the Link for US-Dollar looks like this:
<span class="select-item chang-border" data-spm-anchor-id="a2g0o.home.1000001.i0.650c2145pgspp2">
<a rel="nofollow" href="javascript:;" data-spm-anchor-id="a2g0o.home.1000001.40">USD ( US Dollar )</a>
</span>
You can use the FindElementByCssSelector to access this link:
driver.FindElementByCssSelector("[data-spm-anchor-id=a2g0o.home.1000001.40]").Click()
For EURO it is:
driver.FindElementByCssSelector("[data-spm-anchor-id=a2g0o.home.1000001.43]").Click()

VB WebBrowser click button

On this web page: https://www.youtube.com/upload_defaults
I would like to call a function and then click the "Save" button in the upper right corner.
There is no ID or Name. How can I do this?
You can use the distinct CSS class of the button: account-save-button
In VB.NET, use HtmlDocument.GetElementsByTagName like this:
Private Sub ClickSaveButton()
If (WebBrowser1.Document IsNot Nothing) Then
Dim Elems As HtmlElementCollection
Dim WebOC as WebBrowser = WebBrowser1
Elems = WebOC.Document.GetElementsByTagName("BUTTON")
For Each elem As HtmlElement In Elems
Dim CssClass As String = elem.GetAttribute("classname")
If ((CssClass IsNot Nothing) And (CssClass.Length <> 0)) Then
If CssClass.ToLower().Contains("account-save-button") Then
elem.InvokeMember("click");
Exit For
End If
End If
Next
End If
End Sub
To verify it with just a web browser, try this from your browser's developer console; it works because youtube uses jQuery:
$(".account-save-button").click();
Or pure javascript: document.getElementsByClassName('account-save-button')[0].click();
For reference, here is the button's markup:
<button class="yt-uix-button yt-uix-button-size-default yt-uix-button-primary account-save-button account-action-button" type="submit" onclick=";return true;"><span class="yt-uix-button-content">Save</span></button>
Other thoughts:
This is basically screen scraping, which can lead to brittle applications when the page changes, etc.
Google may already have a web service API for what you are trying to accomplish.. but that's a good question:
What exactly are you trying to accomplish? What is the context? We may be able to suggest a better alternate solution.
Update:
I checked the Youtube API Reference, but I don't see anything for setting preferences for upload defaults.

How can I perform click in web browser control?

I am trying to click a div id button in vb.net, I have the webbrowser included, here is my current code. I'm just trying to click the 'Do Job' on the website, but in vb.net.
WebBrowser1.Document.GetElementById("hunt_job_button100").InvokeMember("click")
This doesn't work, the div id for the website is:
I also need to display a little text from the facebook app itself to a textbox in vb.net, and the div id for the text i want to copy to the vb.net textbox is "energy_value".
Everything on this app is div id
Use this :
webBrowser1.Document.GetElementById("hunt_job_button100").InvokeMember("click")
Or as you are using Class also i suggest to use it :
HtmlElementCollection classButton = webBrowser1.Document.All;
foreach (HtmlElement element in classButton)
{
if (element.GetAttribute("className") == "hunt_job_button")
{
element.InvokeMember("click");
}
}
regards

Content Transition Windows Phone

I have 2 viewboxes in my page and currently I am doing this:
ViewBox1.Visibility = Visibility.Collapsed;
ViewBox2.Visibility = Visibiltiy.Visible;
That means upon some button press, I am hiding first viewbox and showing the second one. Now, upon hiding I want a simple transition animation like viewbox1 sliding out and viewbox2 sliding in, something like this.
I have installed WPF toolkit, but can't figure this out.
Any help is highly appreciated.
Currently I have found this solution, this is actually full page transition but it works for me, I am sharing this code here:
SlideTransition transition = new SlideTransition();
transition.Mode = SlideTransitionMode.SlideLeftFadeIn;
PhoneApplicationPage page = (PhoneApplicationPage)((PhoneApplicationFrame)Application.Current.RootVisual).Content;
ITransition trans = transition.GetTransition(page);
trans.Completed += delegate
{
trans.Stop();
};
trans.Begin();

Update panel in asp.net

I am using two update panel..in nested way.. can i use like this and also
in my project im using clientscript.RegisterScript along with update panel , its not giving any error but , my pop up is not being displayed when i click one item on grid. the pop up is in update panel which is inside (nested)..
can anyone help ???
Thank you
RegisterScript may not work well with updatepanel. use PageRequestManager.add_endRequest method to hook-up client script in this scenario.
if (window.Sys){
var prmx = window.Sys.WebForms.PageRequestManager.getInstance();
prmx.add_endRequest(function() {
alert('insert your code here...');
});
}
also make sure there is no javascript erros during page load.