0

I'm trying to select an e-mail href to grab the text, but no matter what selections I use to try to select the e-mail, my selection doesn't seem to work and I am curious what other ways might exist to fix the problem.

I have used absolute and relative xpath, CSS selector, and id to try to grab the e-mail. I've tried using both visibilityOfElementLocated and elementToBeClickable to no avail. Here is the current iteration I have, just for reference (illustrating both my cssSelector and xpath selector):

wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".email")));
String hire_email = driver.findElement(By.xpath(".//*[@id='information-row-0']/div/div/div[2]/div/div[1]/div")).getText();

Whenever I run the automation, when it gets to the e-mail step, it will wait 15 seconds before it times out which clearly indicates it is not seeing the element.

I use Firebug and Firepath for xpath, so I know my xpaths are not wrong when trying to select the element which is what confuses me the most. What might be causing this element to be unseen and what can I try to do to solve this problem? Please let me know if there is other relevant information needed that is being left out and I'll provide it if I can. Thanks in advance.

As per request, here is the tr and td information in the table where the email resides... (sorry it looks ugly, copying directly from Firefox)

<tr class="information-row opened">
<td class="information-row opened" colspan="8">
<div id="information-row-0">
<div class="information-row-shell" style="overflow: visible; height: 238px;">
<div class="minimal-row row-fluid">
<div class="ja-pulse-container">
<div class="mrg-10 pull-left ja-pulse" style="display: block;">
</div>
<div class="information-row-rest row-fluid">
<div class="row-fluid">
<div class="span4 contact-container row-fluid">
<div class="caption">
<address>
<div class="full-name">
<span class="full-address">
<br>
<span class="full-address"> lanse, MI 49946 </span>
<hr>
<i class="icon icon-mobile-phone"></i>
<abbr title="Phone">Primary:</abbr>
<span class="tel">(432) 777-4444</span>
<br>
<i class="icon icon-phone"></i>
<abbr title="Additional phone">Secondary:</abbr>
<span class="tel">N/A</span>
<br>
<i class="icon icon-shield"></i>
<abbr title="Social Security Number"> SSN: </abbr>
<span class="ssn">(removed, even though this is a fake testing profile)</span>
<br>
<br>

<a class="email" href="mailto:alaiaia@lssiss.com">
<i class="icon icon-envelope"></i>
<span class="email">alaiaia@lssiss.com</span> <!--- I want to grab this --->
</a>
</address>
</div>
lmcphers
  • 468
  • 3
  • 18
  • 1
    need to see some html – Cathal Jun 15 '15 at 14:38
  • Hi Cathal, as per request, i've updated the original with the html block. – lmcphers Jun 15 '15 at 14:42
  • Is the concerned element in a frame ? – Subh Jun 15 '15 at 16:41
  • I don't think so? The strangest thing is I ran the tests on a Windows computer and they were able to get much further. The problem for some reason exists with "information-row-0"; I am not able to easily find any elements in that area at all on my machine, but it is possible on a Windows (my development machine is a Mac). We're currently not sure what is causing this issue. It's actually not with the e-mail at all, I can't grab ANY elements in the information-row-0 row after the first time I get things from it. – lmcphers Jun 15 '15 at 17:55

2 Answers2

1

Do you get any exceptions thrown? if the element is not visible then a NoSuchElementException will be thrown. Other then that, i would suggest making your xpath more readable, something like the following:

String emailAddress = driver.findElement(By.xpath("//span[@class='email']")).getText();
Cathal
  • 1,318
  • 1
  • 12
  • 19
  • I tried to locate it by your suggestion, and I'm getting the same thing to happen where it will just time out. There is no "NoSuchElementException". This is the error I am getting, but pretty sure it refers to our built in function that times out while the tests run. `org.openqa.selenium.TimeoutException: Timed out after 15 seconds waiting for visibility of element located by By.xpath: //span[@class='email']` – lmcphers Jun 15 '15 at 14:54
  • 2
    hmm, that suggests that the element is displayed but cannot be selected for some reason. Without looking at the page directly i cant really help any more! – Cathal Jun 15 '15 at 15:01
  • Thanks anyway. I'll look into finding a different field to grab for the SQL Query we're calling since the e-mail doesn't want to cooperate. – lmcphers Jun 15 '15 at 15:05
0

Can you not locate it like this?

driver.findElement(By.xpath("//span[@class='email']"));
Daniel Stanley
  • 1,050
  • 6
  • 15