问题
Im trying to get the email address from the following code but im not sure how to do it. Any help would be appreciated
<div class="taLnk hvrIE6 fl" onclick="ta.trackEventOnPage('Listing', 'Email', 7741695, 1); return ta.call('ta.locationDetail.checkEmailAction',event,this,'info@email.com', 7741695, '\x41\x6e\x20\x69\x6e\x71\x75\x69\x72\x79\x20\x66\x72\x6f\x6d\x20\x61\x20\x54\x72\x69\x70\x41\x64\x76\x69\x73\x6f\x72\x20\x75\x73\x65\x72\x20\x66\x6f\x72\x20\x41\x6e\x6e\x61\x4c\x65\x6e\x61', 'Restaurant_Url_Restaurant_Review');">
回答1:
You would have to use Selenium to get the value of the onclick attribute and then use JAVA Strings to seperate out the required email.
// find the element and get the attribute value of onclick
String onClickValue = driver.findElement(By.xpath("//div[@class= 'taLnk hvrIE6 fl']")).getAttribute("onclick");
// split the onclick value on ','
String[] allTextArray = onClickValue.split(",");
// iterate through the array and is @ is contained with the text, print text
for (String text : allTextArray) {
if (text.contains("@")) {
System.out.println(text);
return;
}
}
Note: The XPath of the div might be different. I have written it based on what little HTML you posted.
来源:https://stackoverflow.com/questions/33608225/selenium-get-string-value-from-div-onclick-element