How can I access to click on 2nd link inside TextView? So far I tried:
AndroidElement d = (AndroidElement) driver.findElement(By.xpath("//android.widget.TextView[#text='Notice']"));
d.click();
And using:
driver.findElement(By.Id("com.optimum.rdvr.mobile:id/toc_text"));
just clicks on 1st link. And I need to get 2nd link. I want to click on "Mobile Privacy Notice" Any one has suggestion?
You can use Linkify
String termsOfUse = getResources().getString(R.string.terms_of_use);
String privacyNotice = getResources().getString(R.string.privacy_notice);
legalDescription.setText(
String.format(
getResources().getString(R.string.message),
termsOfUse,
privacyNotice )
);
//add the links
Pattern privacyNoticeMatcher = Pattern.compile(privacyNotice);
Linkify.addLinks(legalDescription, privacyNoticeMatcher , "privacy:");
Pattern termsOfUseMatcher = Pattern.compile(termsOfUse);
Linkify.addLinks(legalDescription, termsOfUseMatcher , "termsOfUse:");
via Multiple Clickable links in TextView on Android
Related
In my application, there are more than 50 links starting with "pw_listing_widget_tabs_list_ul']/li". I want to click on the randomly generated link. I have written below, but it is failing to click the link.
List<WebElement> links= driver.findElements(By.xpath("//ul[#id='pw_listing_widget_tabs_list_ul']/li"));
int count=links.size();
System.out.println("Total links are: " +count);
Random r = new Random();
int linkNo = r.nextInt(count);
System.out.println("Random Link# " +linkNo);
WebElement link = links.get(linkNo);
String text = link.getText();
System.out.println("Text: " + text);
Thread.sleep(3000);
link.click();
I have even tried to click the link using text, but the text is coming to long to & it is failing to click.
If you want to click on the link (anchor tag), try to specifically point it to the tag a.
Can you please change your XPath to
//ul[#id='pw_listing_widget_tabs_list_ul']/li/a
List<WebElement> links= driver.findElements(By.xpath("//ul[#id='pw_listing_widget_tabs_list_ul']/li/a"));
Q2: I have even tried to click the link using text, but the text is coming to long to & it is failing to click.
Ans2: Your element point to <li> and when u use link.getText();it will going to return all the text inside <li> and not inside {ANCHOR-TAG-TEXT}
Try to use the below XPATH:
//ul[#id='pw_listing_widget_tabs_list_ul']/li/a
Note: If possible share error code and HTML
I'm working on an app that generates passwords randomly using the array. The password is in TextView. Everything is good unless I want to generate a new password second time. How can I "delete" the old text (password) from the TextView and replace it with the new one using the same button?
Here are the variables that I'm using:
EditText dlugosc;
String haslo = "";
String pustak = "";
TextView haslo0;
And this is a code that I use to generate a password:
(znaki is the name of array)
dlugosc = findViewById(R.id.password_len);
haslo0 = findViewById(R.id.password);
String yui = dlugosc.getText().toString();
int x = Integer.parseInt(yui);
for(int i = 0; i < x; i++){
int Index = generator.nextInt(znaki.length);
haslo = znaki[Index] + haslo;
}
I have already tried doing an if structure:
if (haslo0 != null){
haslo0.setText(pustak);
haslo0.setText(haslo);
}
else
haslo0.setText(haslo);
But it doesn't help :(
When I want to have 7 chars in the password and click the button first time, the result is correct e.g. PKAjzQL. But when I click the button second time, the result is nBzcRjQPKAjzQL instead of nBzcRjQ.
Why are you appending the old string haslo behind the newly generated one in haslo = znaki[Index] + haslo;
Probably that's why you are getting output like that. Can you please try just setting newly generated password into the textview like
haslo = znaki[Index];
And then try to set text in the text view using haslo0.setText(haslo);
How can I "delete" the old text (password) from the TextView and replace it with the new one using the same button?
The problem is not to "delete" the old text, the problem is that you have to clear the list for example, every time user clicks on the Button you clear the list doing : znaki.clear(), then it will only show the new password generated.
If you see your output :
First output :
PKAjzQL --> This is correct
Second output :
nBzcRjQPKAjzQL --> this is the new output + the old one
Can you give the code of the OnClickButton? And why are you setting the same TextView with diferents Strings when you click?
haslo0.setText(pustak);
haslo0.setText(haslo);
?
I have a text in which there is indicator tag that indicate from where i will make text underline, I want to make text underline from that indicator also want to remove indicator so that it wont appear in string, here is what I'm trying:
String consent = "By clicking this, you confirm you understand the services provided by your Health at Hand doctor and give <clickable>consent</clickable> to proceed.";
int i1 = consent.indexOf(">");
int i2 = consent.indexOf("</");
consentCheck.setMovementMethod(LinkMovementMethod.getInstance());
consentCheck.setText(consent, CheckBox.BufferType.SPANNABLE);
consent = consent.replace("</clickable>", "");
consent = consent.replace("<clickable>", "");
Spannable mySpannable = (Spannable)consentCheck.getText();
mySpannable.setSpan(clickableSpan, i1+1, i2 , Spannable.SPAN_INCLUSIVE_INCLUSIVE);
If you want to display the text in TextView you could replace "clickable" tags with "u" tags and then use Html.fromHtml() in setText:
String consent = "By clicking this, you confirm you understand the services provided by your Health at Hand doctor and give <clickable>consent</clickable> to proceed.";
consent = consent.replace("<clickable>", "<u>").replace("</clickable>", "</u>");
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
tvConsent.setText(Html.fromHtml(consent, Html.FROM_HTML_MODE_LEGACY));
} else {
tvConsent.setText(Html.fromHtml(consent));
}
EDIT:
If u want to edit "consent" part freely you could split the text into three parts and then edit each part independently
String consent = "By clicking this, you confirm you understand the services provided by your Health at Hand doctor and give <clickable>consent</clickable> to proceed.";
String start = "<clickable>";
String end = "</clickable>";
String part1 = consent.substring(0, consent.indexOf(start));
String part2 = consent.substring(consent.indexOf(start)+start.length(),consent.indexOf(end));
String part3 = consent.substring(consent.indexOf(end), consent.length()).replace(end, "");
I've got the following HTML
<div id="colLeft_OrderGroups" class="GroupList GroupList_Left">
<div class="SelectList" style="height:516px;">
<div class="DialogSubtitle">Available groups</div>
<ul class="ui-selectable" id="grdAvailableGroups" style="width:100%; margin-right:2px">
<li value="10929">AppraisersGroupTest</li>
</ul>
</div>
</div>
How do I select the option based off the "AppraisersGroupTest" text?
There will be multiple values in the list soon, so I need to be able to specify the text.
I have tried the answer in this post, but I'm getting syntax errors I cannot resolve.
Looking at your HTML, I'm going to assume that the value of the desired LI is going to always be "10929" for your desired "AppraisersGroupTest." With that info, you can use the code below.
String value = "10929";
WebElement dropdown = driver.findElement(By.id("grdAvailableGroups"));
dropdown.click(); // assuming you have to click the "dropdown" to open it
dropdown.findElement(By.cssSelector("li[value=" + value + "]")).click();
If it turns out that is not a good assumption, you can use the code below to search for the desired text and click the element.
String searchText = "AppraisersGroupTest";
WebElement dropdown = driver.findElement(By.id("grdAvailableGroups"));
dropdown.click(); // assuming you have to click the "dropdown" to open it
List<WebElement> options = dropdown.findElements(By.tagName("li"));
for (WebElement option : options)
{
if (option.getText().equals(searchText))
{
option.click(); // click the desired option
break;
}
}
You can achieve this using one liner xPath as below :-
String text = "AppraisersGroupTest";
WebElement el = driver.findElement(By.xpath("//div[#id = 'colLeft_OrderGroups']/descendant::li[text() = '" + text + "']"));
el.click();
Hope it will help you...:)
'For anyone who may need it
Sub Memlogin()
'Login Members Profile
Dim IE As New selenium.WebDriver
Set IE = New ChromeDriver
With IE
.Get "Your URL"
.FindElementByName("Uni_user_id").SendKeys ("Your User ID")
.FindElementByName("password").SendKeys ("Your Password")
.FindElementById("Uni_login_button").Click
'Select Profile Section
.Get "Secondary URL if Needed"
.Wait Now + TimeValue("00:00:10")
End With
'Select Desired Tab
Dim MTab, Tabs, User As selenium.WebElement
Set MTab = IE.FindElementByTag("ul")
Set Tabs = IE.FindElementByClass("li class-name ")
Set User = IE.FindElementByXPath("//a[text()=""li innerText""]")
IE.Actions.MoveToElement(User).Click(User).Perform
IE.Wait Now + TimeValue("00:00:20")
End Sub
List item
I'm creating a NetBeans plugin, and would like the Actions I declare to appear grouped together in their own submenu when right-clicking on a Java file. I'm able to get the Action to appear within the context menu, however I am unable to put it into a submenu. My current Action annotations look like this...
#ActionID(
category = "Source",
id = "net.myproj.actions.DoMyAction"
)
#ActionRegistration(
displayName = "#CTL_DoMyAction"
)
#ActionReferences({
#ActionReference(path = "Loaders/text/x-java/Actions", position = 2950, separatorBefore = 2925, separatorAfter = 2975),
#ActionReference(path = "Editors/text/x-java/Popup", position = 2950, separatorBefore = 2925, separatorAfter = 2975)
})
#Messages("CTL_DoMyAction=Foo...")
I've tried adding another path under Loaders/text/x-java/Actions, but that doesn't work. Same with Editors/text/x-java/Popup. Is there a way that I could have my Actions grouped together within their own separate submenu?