How to input a capital letter by using "solo.sendkey()"? - robotium

I'm using Robotium to test my Android app. In a webView, I need input a capital letter by solo.sendkey(). But, I found there are only lowercases in KeyEvent.KEYCODEs.
I tried to use this.getInstrumentation.senKeySync(); but, it is no use.
Can I input capital letter by solo.sendkey()?

Could you please try with modifier key: KEYCODE_CAPS_LOCK?
There are two more options: 1) KEYCODE_SHIFT_LEFT and 2) KEYCODE_SHIFT_RIGHT.
Ideally, sending the KEYCODE_CAPS_LOCK keyEvent first should help to you send capital letter in the second event.
You can find more details about KeyEvents here:
http://developer.android.com/reference/android/view/KeyEvent.html

Related

Can t find the xpath for Following button instagram for selenium

I try to get the xpath for the following button on instagram making an automate unfollowing soft. enter image description here
I found it just like this:
driver.find_element_by_xpath('//div[#class="qF0y9 Igw0E rBNOH YBx95 ybXk5 _4EzTm soMvl "]').click()
But i want to itterate over all ,,Following" Buttons , but like this is stuck at the first one!
This is my Code:
fBody = driver.find_element_by_xpath("//div[#class='isgrP']")
for i in range(1, 1500):
driver.find_element_by_xpath('//div[#class=" qF0y9 Igw0E rBNOH YBx95 ybXk5 _4EzTm soMvl "]').click()
#driver.find_element_by_xpath("//*[text()='Following']").click()
print("Am apasat follow")
sleep(5)
driver.find_element_by_xpath('//button[#class="aOOlW -Cab_ "]').click()
sleep(5)
driver.execute_script('arguments[0].scrollTop = arguments[0].scrollTop + arguments[0].offsetHeight;', fBody)
print("Ma bag la somn 1 min")
sleep(2)
print("salut")
Selenium does Not "like" empty or white spaces in the attributes.
I suggest using a CSS selector and using *= in order to find text contains:
driver.find_element_by_CSS('//div[class*="qF0y9"][class*="Igw0E"]').click();
Avoid using white or empty spaces and, underscores (_) and hyphens (-) for the element's attributes.
I think the classes on the elements change as yours do not match with mine. Here is a more generic XPath that matches the "following" button.
//div//button[div[text()='Following']
When using this in a test I found it instantly failing unless I surrounded it with an explicit wait condition.
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div//button[div[text()='Following']"))).click();
Ill post my example when Instagram stops giving me connectivity issues.

How to find an element containing #nbsp; in text?

I've an element with html -
<h3>App-1 Playground Login</h3>
I want to identify it with entire text - App-1 Playground Login, but causing issues to identify it. Please help how this element can be identified.
Please use the below xpath. I have already tested that and it is working fine. In the second argument of the translate method you need to type "ALT+0160" and in the third argument you will have to put just a normal space.
//h3[contains(translate(text(),' ',' ' ), 'App-1 Playground Login')]
One of the way to select your title could be :
//h3[text()= concat('App-1 Playground',codepoints-to-string(160),'Login')]
Works fine on http://xpather.com/

Unable to identify Web object in UFT for webpage?

SystemUtil.Run "iexplore.exe", "https://www.jetairways.com/EN/IN/Home.aspx"
wait (7)
Set traverse=Browser("Jet Airways: Airlines").Page("Jet Airways: Airlines")
traverse.WebEdit("placeholder:=From").Click
traverse.Link("acc_name:= This link will open Popup window for airport selection. ").WebElement("innerhtml:=All Airports","innertext:=All Airports","outerhtml:=<strong>All Airports </strong>").Click
traverse.WebTabStrip("html id:=ToC").Link("innerhtml:=Africa","innertext:=Africa").Click
Set oDesc = Description.Create
oDesc( "micclass" ).value = "Link"
oDesc( "href" ).value = "https://www.jetairways.com/EN/IN/Home.aspx#"
Set rc=Browser("creationtime:=0").Page("micClass:=page").ChildObjects(oDesc)
msgbox rc.count
UFT is not bale to identify the link, lets say, Johanesber or Port Elizabeth,etc
This is actually not working. Have tried many ways .
Can some one help me fix this?
The following code works for me, I cleaned up some of the spaces (and simplified the description a bit). I don't understand what you were trying to accomplish with the last lines of your script (counting the links).
I think the problem you were facing was probably to do with the fact that when you use descriptive programming (either inline with := or using a Description object), the values are used as regular expressions and not as plain strings. This means you have to escape regular expression characters (in this case ( and )) or else the values won't match.
Set traverse=Browser("Jet Airways: Airlines").Page("Jet Airways: Airlines")
traverse.WebEdit("placeholder:=From").Click
traverse.Link("acc_name:=This link will open Popup window for airport selection.").WebElement("html tag:=strong").Click
traverse.WebTabStrip("html id:=ToC").Link("innerhtml:=Africa","innertext:=Africa").Click
traverse.Link("innertext:=Port Elizabeth \(PLZ\)").Click ' Note \( and \)
Try to write the link object and the pop up window object in two different lines
traverse.Link("acc_name:= This link will open Popup window for airport selection. ")
traverse.WebElement("innerhtml:=All Airports","innertext:=All Airports","outerhtml:=<strong>All Airports </strong>").Click
also try to use Regex if the property values contains spaces or symbols.

Calabash-android: How do I read text which comes from an API?

I want to read the text which comes from API end, When I query (query("*")) it does not appear on the calabash-android console.
wait_for_text(text, timeout: 10) does not work either.
query "all * marked'Email field can not be empty'"
Calabash doesn't return results that are not visible by default. So if the error message is on the screen but just invisible, using the all operator should do the trick.
In android two different message can show in edit text field by using hint text and error text
if its hint text use this:
query("* id:'edit_text_id'", :hint)
if its error message use this:
query("* id:'edit_text_id'", :error)
Normally these kind of text messages won't show by querying -> query("*")

Simulate TAB keypress event in Selenium RC

I need to simulate a tab keypress in Selenium RC, using the Java API.
I do this after having entered some text using:
selenium.type(input, "mytext");
I've tried 3 alternatives to get the tab working:
selenium.keyPress(input, "\\9");
and:
selenium.focus(input);
selenium.keyPressNative("09");
and even:
selenium.getEval("var evt = window.document.createEvent('KeyboardEvent');evt.initKeyEvent ('keypress', true, true, window,0, 0, 0, 0,0, 9,0);window.document.getElementsByTagName('input')[2].dispatchEvent(evt);")
The best I can get is a "tab space" to be inserted after my text so I end up with this in the input field:
"mytext "
What I actually want is to tab to the next control. Any clues? Thanks!
(Note: I have to use tab and can not use focus or select to chose the element I want to go to, for various reasons, so no suggestions along these lines please!)
selenium.keyPressNative(java.awt.event.KeyEvent.VK_TAB + "");
I don't use the Java API, but this post from google groups suggests it is your solution. I can't imagine that "9" is different from "09" in your question, but give it a try?
Try the official TAB char: \t or \u0009
Some functions may used Onblur. It will trigger the function when the field lose the key focus. here we can use fireEvent with "blur" or "focus" command as follows:
command: fireEvent
target: id=your_field_identification
value: blur
Reference: http://qaselenium.blogspot.com/2011/01/how-to-triger-tab-key-in-selenium.html
Improvising Ryley's answer, we can use
selenium.keyDownNative(java.awt.event.KeyEvent.VK_TAB + "");
selenium.keyUpNative(java.awt.event.KeyEvent.VK_TAB + "");
I tried this method for VK_CONTROL in IE and it worked good.
Use typeKeys():
Quoting the above link:
Unlike the simple "type" command, which forces the specified value into the page directly, this command may or may not have any visible effect, even in cases where typing keys would normally have a visible effect. For example, if you use "typeKeys" on a form element, you may or may not see the results of what you typed in the field.
In some cases, you may need to use the simple "type" command to set the value of the field and then the "typeKeys" command to send the keystroke events corresponding to what you just typed.