How do I get the email address from this html snippet?
As there are thousand of leads like this in a certain webpage and the text within it is not always found as it is seen here.
The only common thing is the email address located in the first position.
How can I get the email address and ignore the rest?
These are the elements:
<div class="gm_popup"><div class="gm_name">Adel Outfitters</div><div class="gm_address">1221 W 4th St</div><div class="gm_location">Adel, Georgia 31620<div style="display:none" class="w3-address-country">United States</div></div><div class="gm_phone"><span class="gm_phone_label">P:</span> 229-896-7105</div><div class="gm_email">adeloutfitters#yahoo.com<div><div class="gm_website">https://www.facebook.com/pages/Adel-Outfitters/132735763434461</div><br><a target="_blank" class="directions-link" href="http://maps.google.com/?saddr=+&daddr=1221+W 4th St, Adel, Georgia, 31620">Directions<span class="w3-arrow">different stuffs</span></a></div></div></div>
What I tried:
Set post = html.getElementsByClassName("gm_email")(0)
MsgBox post.innerText
The result:
adeloutfitters#yahoo.com
https://www.facebook.com/pages/Adel-Outfitters/132735763434461
Directionsdifferent stuffs
Expected output:
adeloutfitters#yahoo.com
The closing </div> tag is further down which is why you are getting the extra text. Can you chop off anything after a new line? Or check each word in the string and save the one with "#" in it? Bad way of going about it, but it would probably work...
Related
If I didn't use verbatim with Text
Ex:
Text("Reach out to us on info#eyva.io for any queries!")
.foregroundColor(Color.white)
.font(Font.custom("Poppins-Regular", size: getFontSize(value: 16)))
Output:
And, if I used verbatim with
Text(verbatim: "Reach out to us on info#eyva.io for any queries!")
Ex:
Text(verbatim: "Reach out to us on info#eyva.io for any queries!")
.foregroundColor(Color.white)
.font(Font.custom("Poppins-Regular", size: getFontSize(value: 16)))
Output:
Email clickable functionality not working if I used verbatim with Text()
I want to with email clickable.
Try the below code It will help you:
Text(.init("Reach out to us on [cinfo#eyva.io](cinfo#eyva.io) for any queries!"))
.accentColor(.red)
here in the () round bracket, you have to write the link and in [] square bracket the respective text you want to see, here you want to show the email so in both brackets I wrote the email id modify as you want.
i'm trying to submit password field and a confirm password field. they both dont have ID and have same xpath, the only difference is that first field with label Enter password xpath have [1] and the second field with label Confirm password xpath have [2].
here is the first one:
/html/body/div[1]/div/div[2]/div/div[2]/div/div[1]/label/input
and here is the second one:
/html/body/div[1]/div/div[2]/div/div[2]/div/div[2]/label/input
Xpath helper chrome plugin also give the same.
From the first one:
/html/body/div[#class='app']/div[#class='layout']/div[#class='router-
view']/div[#class='signup-form']/div[#class='onboarding password-
form']/div/div[#class='password-form__input-pass'][1]/label[#class='cs-
input']/input[#class='cs-textstyle-input-text cs-input__input cs-input__input--
medium']
and from the second one:
/html/body/div[#class='app']/div[#class='layout']/div[#class='router-
view']/div[#class='signup-form']/div[#class='onboarding password-
form']/div/div[#class='password-form__input-pass'][2]/label[#class='cs-
input']/input[#class='cs-textstyle-input-text cs-input__input cs-input__input--
medium']
so for now i have this code which submit the first field (Enter password):
password = driver.find_element(By.XPATH, "//input[#class='cs-textstyle-input-text cs-
input__input cs-input__input--medium']")
password.send_keys("ewra5RT#T6")
how can i do for the second field to confirm the password?
I suppose it should be something like:
password_confirm = driver.find_element(By.XPATH, "//input[#class='cs-textstyle-input-
text cs-input__input cs-input__input--medium'][2]")
but I can not figure out the right syntax...?
Please help and thanks.
HTML for both fields are also the same, here:
for the first one:
<input data-v-6484adb0="" type="password" required="required"
class="cs-textstyle-input-text cs-input__input cs-input__input--
medium">
and second:
<input data-v-6484adb0="" type="password" required="required"
class="cs-textstyle-input-text cs-input__input cs-input__input--
medium">
maybe I'm missing something, but why you don't use the full xpaths you mentioned above?
or xpath axis and those label elements you mentioned?
but if you still want to use your approach, then simply replace
[2]
with
position() = 2
in appropriate manner
I am trying to write a script to click an icon which is a part of the table header. Each column in the table has this icon in it (ascending order and descending order sorting icons). I am using Geb to do this. Here is how I am trying to do it:
In my SortingSpec.groovy file:
header.closest("div.customSortDownLabel").click()
I also tried
header.siblings('div.customSortDownLabel').first().click()
In the SortingPage.groovy file:
header {
grid.$(class: 'div.customHeaderLabel', text: 'Country')
}
In my html:
<div>
<div class="customHeaderLabel">{{params.displayName}}</div>
<div *ngIf="params.enableSorting" (click)="onSortRequested('asc', $event)" [ngClass]="ascSort" class="customSortDownLabel">
<i class="fa fa-long-arrow-alt-down"></i></div>
<div *ngIf="params.enableSorting" (click)="onSortRequested('desc', $event)" [ngClass]="descSort" class="customSortUpLabel">
</div>
None of them worked for me. It is not able to find the selector. Any suggestions are appreciated.
Error I see is:
geb.error.RequiredPageContentNotPresent: The required page content 'header - SimplePageContent (owner: SortingGrid, args: [], value: null)' is not present
That error looks like header isn't matching. Assuming that grid matches, and you're using some Javascript framework like Angular to substitute 'Country' for params.displayName, I would guess that maybe Geb is failing to find header before 'Country' is substituted. So, I would try making header wait for it:
header(wait: true) { grid.$(class: 'div.customHeaderLabel', text: 'Country') }
By the way, closest() goes in the wrong direction, to an ancestor, but siblings() looks good.
siblings() didnt work for me but next() worked for me. next() grabs the next sibling elements of the current context elements.
Example:
1. header.next().click() clicks the very next sibling
header.next("div.customSortDownLabel").click() looks for the very next sibling with the matching selector of 'div.customSortDownLabel' and then clicks it.
How to change the font color of Hello alone in "Hello World" using javascript/some other method?
I tried the following code,
var s= session.getCommonUserName()
s.fontcolor("green")
"Hello"+" "+ s.toUpperCase()
where i tried to change just the color of the username alone. But it failed.
I wouldn't bother to send down unformatted HTML to the client and then let the client do the JavaScript work. You create a computed field and give it the data type HTML (that keeps HTML you create intact) and use SSJS. So no JS needs to execute at the client side:
var cu = session.getCommonUserName();
return "Hello"+" <span style=\"color : green\">"+ cu.toUpperCase()+"</span>";
Don't forget to cross your t, dot your i and finish a statement with a semicolon :-)
If you want to do it with client java script, then you must do something like this:
dojo.style("html_element_id", "color", "green");
So in your case you can have have something like:
<p><span id="span1">Hello</span> World.</p>
Or you can do it directly if you don't need to change it with CJS:
<p><span style="color:green">Hello</span> World</p>
one way to do it is to wrap your 'hello' in a html span and then change the color of that span.
<span id='myspan'>hello</span> world
javascript code:
document.getElementById('myspan').style.color='green';
Went old school on this one...
Say you want to put your formatted text in a div
<div id="test">
</div>
Then you need the following javascript to do so:
div = document.getElementById("test");
hello = document.createElement("span");
hello.innerHTML = "Hello"
hello.style.color = "green";
div.appendChild(hello);
div.appendChild(document.createTextNode(" world!"));
I have a portion of HTML that looks similar to:
<table><tbody><tr>
<td><div> Text Goes Here </div></td>
<td> ... rest of table
There are no IDs, no Titles, no descriptors of any kind to easily identify the div that contains the text.
When an error occurs on the page, the error is inserted into the location where "Text Goes Here" is at (no text is present unless an error occurs). Each error contains the word "valid".
Examples: "The form must contain a valid name" or "Invalid date range selected"
I currently have the Watir code looking like this:
if browser.frame(:index => 0).text.includes? "valid"
msg = # need to get full text of message
return msg
else
return true
end
Is there any way to get the full text in a situation like this?
Basically: return the full text of the element that contains the text "valid" ?
Using: Watir 2.0.4 , Webdriver 0.4.1
Given the structure you provided, since divs are so often used I would be inclined to look for the table cell using a regular expression as Dave shows in his answer. Unless you have a lot of nested tables, it is more likely to return just the text you want.
Also if 'valid' may appear elsewhere then you might want to provide a slightly larger sample of the text to look for
. browser(:cell => /valid/).text
Try this
return browser.div(:text => /valid/).text
or
return browser.table.div(:text => /valid/).text
if the valid is not found, it should return nil.