I have a window that displays my tweets in a label.
My tweets come from my FB page statuses and if i have put a pic or write more than 140 characters then i get a link in tweet to the actuall post.
I wonder if there is any way to get the label text to split so i can point the link into an url to open in webview
This is how far i have got:
var win = Ti.UI.currentWindow;
win.showNavBar();
var desc = Ti.UI.createLabel({
text: win.data,
font:{
fontSize:'20dp',
fontWeight:'bold'
},
height:'300dp',
left:'5dp',
top:'10dp',
color:'#111',
touchEnabled:true
});
win.add(desc);
desc.addEventListener('click',function(e){
var v = desc.text;
if(v.indexOf('http') != -1){
// open new window with webview
var tubeWindow = Ti.UI.createWindow({
modal: true,
barColor: '#050505',
backgroundColor: '#050505'
});
var linkview = Ti.UI.createWebView({
url: e.v,
barColor: '#050505',
backgroundColor: '#050505'
});
// Create a button to close the modal window
var close_modal = Titanium.UI.createButton({title:'Stäng'});
tubeWindow.rightNavButton = close_modal;
// Handle close_modal event
close_modal.addEventListener('click', function() {
tubeWindow.close();
});
tubeWindow.add(linkview);
tubeWindow.open({
modalTransitionStyle: Ti.UI.iPhone.MODAL_TRANSITION_STYLE_FLIP_HORIZONTAL,
});
}
});
win.open();
What i´ve been told i need to split the win.data to get the link. (win.data is the tweet)
now i just have: url: e.v, i need to get the link out
Any ideas on how this can work?
Thanx
//R
I did a similar thing a while ago. pull down the tweet(s) run the text through a regular expression to pull out a URL.
What I did was put each tweet in a tableview row, and set the tableview row to hasChild=true if the regular expression returned anything, then onClick of a tableView row, if hasChild == true open a webview with the given URL (stored in the row).
A regualr expression like the one here should work:
http://www.geekzilla.co.uk/view2D3B0109-C1B2-4B4E-BFFD-E8088CBC85FD.htm
So something like:
str= <<tweet text>>;
re= <<URL expression>>;
check=str.match(re);
now check contains either null or a url.
Related
I need to write a selenium with java code where I need to perform all image font and size check but there is a pagination
where the default page set is 50 what if I need to perform font and size check in each page. I have attached my code but it will
check only first page.
Scenario:
1.On Parent page only 50 links are displayed I need to click on each record and perform font/size check in same page
I need to again click on next page and perform same font/size check after completing it should navigate to parent page and
again click on other records and vice versa but again we have pagination on parent page as well.
List<WebElement> list=driver.findElements(By.xpath("//a[#class='primary-cell-text link']"));
System.out.println(list.size());
//Here Pagination code is required ???
ArrayList<String> hrefs = new ArrayList<String>(); //List for storing all href values
for (WebElement var : list) {
System.out.println(var.getText()); // fetch the text present between the anchor tags
System.out.println(var.getAttribute("href"));
hrefs.add(var.getAttribute("href"));
System.out.println("*************************************");
}
//Navigating to each link
int i=0;
for (String href : hrefs) {
driver.navigate().to(href);
System.out.println((++i)+": navigated to URL with href: "+href);
Thread.sleep(3000); // To check if the navigation is done properly.
System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
Thread.sleep(5000);
//Here Pagination code is required ????
//Below code is to perform action
List<WebElement> block=driver.findElements(By.xpath("//*[text()='High' or text()='Medium' or text()='Low']/preceding-sibling::div"));
for(int b=0;b<block.size();b++) {
System.out.println(block.get(b).getCssValue("height"));
System.out.println(block.get(b).getCssValue("width"));
String h=block.get(b).getCssValue("height");
String w=block.get(b).getCssValue("width");
if(h.equals("16px") && w.equals("16px")) {
System.out.println("Height/Width is Matching ");
}
else {
System.out.println("height/Width not matching");
}
}
Thread.sleep(3000);
//High Color Check
List<WebElement> high=driver.findElements(By.xpath("//*[text()='High']/preceding-sibling::div"));
for(int h=0;h<high.size();h++) {
WebElement hvar=driver.findElement(By.xpath(("(//*[text()='High']/preceding-sibling::div)["+(h + 1)+"]")));
String highColor=hvar.getCssValue("background-color");
System.out.println(highColor);
String hexHighcolor=Color.fromString(highColor).asHex();
System.out.println(hexHighcolor);
if(hexHighcolor.equals("#e11900")) {
System.out.println(": High color is matching i.e:#e11900");
}
else {
System.out.println(": Low color is not matching :#e11900");
}
}
You have to add logic for going to the next page like in web pages, we can either scroll down further or click on next page to perform pagination.
So for all pages that you have got, you can call a separate function to check your css values onto them.
i am trying to parse data from a webpage which is structured in a way like, 20 records per sheet
i am able to get the first 20 records and then i have to move to the second sheet, the second sheet link is as shown below
2
the href element has some javascript that loads the next 20 records. when it does, the url remains same.
the Javascript which is called
var theForm = document.forms['aspnetForm'];
if (!theForm) {
theForm = document.aspnetForm;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
how can i handle this part in jsoup? is it even possible?
thanks in advance.
I want to take picture using webcam in my java web application.Now to do this i am using Photobooth.js that provide facility to click images in web applications.
Now my problem is that as soon as I click button to take picture I want to save it in my computer with a name say temp.png in a specified folder say C:/MyPictures.But the picture being clicked by using photobooth.js provides a dataUrl of the form :
data:image/png;base64,iVBORw0KGgoAAAANSU and so on a long string.
How can i get image to specified location now?
My code for using photobooth and displaying the clicked image is as follow:
<script type="text/javascript">
$(document).ready(function () {
$('#photo').photobooth().on("image", function (event, dataUrl) {
alert(dataUrl);
$("#gallery").show().html('<img src="' + dataUrl + '" >');
});
});
</script>
In html part :
<div id="photo"></div>
<div id="gallery"></div>
Here is the .js file am using :
https://github.com/WolframHempel/photobooth-js/blob/gh-pages/photobooth_min.js
I got this code to convert dataURL to blob .Can it be helpful in getting me image to particular location ?
function dataURLtoBlob(dataUrl) {
// Decode the dataURL
var binary = atob(dataUrl.split(',')[1]);
// Create 8-bit unsigned array
var array = [];
for (var i = 0; i < binary.length; i++) {
array.push(binary.charCodeAt(i));
}
// Return our Blob object
return new Blob([new Uint8Array(array)], {
type: 'image/png'
});
}
Are you just trying to trigger a download of the image? You can download a file in javascript using an anchor element with a download attribute and firing a click event on it. In this case you could set the anchors href to be the dataURL of your image.
function download(dataUrl, filename) {
var download = document.createElement('a');
download.href = dataUrl;
download.target = '_blank';
download.download = filename;
var evt = document.createEvent('MouseEvents');
evt.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0,
false, false, false, false, 0, null);
download.dispatchEvent(evt);
}
See this fiddle:
http://jsfiddle.net/edAAe/1/
I am using Web driver 2.31 with Java. It seems the web driver is unable to perform click action on an input element having onclick() attribute.
The input element I need to perform click action on is having the following attributes - id (which is a random generated number), class, type=button, onclick, onmouseout, onmouseover, title and value.
I'm able to fetch the values of title and value attributes which means that the web driver is able to recognize the input element but is not able to perform click action on it.
I have tried with the following:
webdriver.findElement(By.xpath("xpath for the input")).click()
webdriver.findElement(By.xpath("xpath for the input")).sendKeys(Keys.ENTER);
new Actions(webdriver).moveToElement(webdriver.findElement(By.xpath("xpath for the input"))).click().perform();
None of the above options are working.
Do you get any exceptions from element.click()? It it enabled and visible? One of the problems we had was that WebDriver didn't handle position:static elements correctly, so during playback it would cover the button (and you won't see it on screenshot) and it would throw exception "Element is not clickable at point".
We had similar problem with element and had following code that did work sometimes (but also not 100% of times):
element.click();
if("button".equals(tagName)) {
if(element.isEnabled() && element.isDisplayed())
element.sendKeys(Keys.ENTER);
}
But the problem disappeared itself after upgrading WebDriver and we removed sendKeys(ENTER), also it was working fine in 2.29.0.
I faced exactly same problem in my project. The issue was not to locate the element but the onClick() event was not firing.
Then i found out that something else was there which stopped from the event to fire. I had used java script to enable the date picker box & did this,
((JavascriptExecutor)driver).executeScript ("document.getElementById('txtOriginDate').removeAttribute('readonly',0);");
WebElement originDateBox= driver.findElement(By.xpath(prop.getProperty("originDateBox")));
originDateBox.clear();
originDateBox.sendKeys("9-Dec-2014"); //Enter date
Developer designed this in such a way that if you don't use date picker to select date, a specific variable was not set. Which eventually made the **onclick event not to fire.
The date picker code was something like this,
var jsoncustdate = "";
var jsonorigindate = "";
function onSelectCalender( StrDt, obj )
{
if ( !varReadonly ) {
if ( $( "#txtCustDescisionDate" ).attr( "IsDisable" ) == "FALSE" )
{
if ( obj.id == "txtCustDescisionDate" )
{
custobjDt = new Date( obj.selectedYear, obj.selectedMonth,obj.selectedDay, 0, 0, 0, 0 );
jsoncustdate = custobjDt.getTime();
jsoncustdate = "\/Date(" + jsoncustdate + ")\/";
DisabledBtnStage();
// $("#txtFromDate").datepicker("option", "maxDate", objDt);
}
if ( obj.id == "txtOriginDate" )
{
var objDt = new Date( obj.selectedYear, obj.selectedMonth,obj.selectedDay,0, 0,0,0 );
jsonorigindate = objDt.getTime();
jsonorigindate = "\/Date(" + jsonorigindate + ")\/";
DisabledBtnStage();
// $("#txtToDate").datepicker("option", "minDate", objDt);
}
}
elogCommon.CheckMandatory();
}
}
I finally used date picker in normal way & the event fired smoothly.
I hope this answer will help . .cheers !!!
Since not all of our users are guaranteed to support the HTML 5 placeholder attribute, I was trying to build a workaround for it in JavaScript:
$(document).ready(function() {
var searchInColumn = $('#searchInColumn').text();
$(".ui-widget-glossary-editor-column-filter").on('focus', function() {
var $this = $(this);
if ($this.val() == searchInColumn) {
$this.val('');
$this.css('color', '#444444');
}
}).on('blur', function() {
var $this = $(this);
if ($this.val() == '') {
$this.val(searchInColumn);
$this.css('color', '#c9c9c9');
}
}).blur();
});
While that works as it's supposed to, this now of course poses the problem that an actual (localized) text is present in the input text field, triggering the datatable filter. Can I somehow intercept the PrimeFaces datatable filtering in order to treat this localized placeholder text as an empty string?
Thanks for your suggestions and best regards
Pascal
You mean you placeholder being interpreted as value and sent to server ?
If so you better use jq-watermark to apply the watermark properly...