lundi 20 mai 2019

Is there a possibility to automate the process of deleting user in Wordpress Admin using Selenium?

I'm trying to make an automated test which consists of registering a new user and deleting it, so this test could be run multiple times. On wp-admin/users.php there is a table, where each user is formatted as . Can I get user id (specifically it's number), if I have user's email?

Right now I'm trying to make a list of Web Elements, convert it to string (getAttribute("outerHTML") and reduce its size to 1 element, that contains email. But I don't know how to deconstruct the string, so I can get the needed id number.

List<WebElement> trTags = driver.findElements(By.tagName("tr"));
List<String> users = trTags.stream().filter(item -> item.isDisplayed()).map(item->item.getAttribute("outerHTML")).collect(Collectors.toList());
users.removeIf(elem -> !elem.contains("test@test.com"));
users.stream().forEach(elem -> System.out.println(elem));

This is what the result looks like

<tr id="user-20">
<th scope="row" class="check-column">
<label class="screen-reader-text" for="user_20">Select *username*</label>
<input type="checkbox" name="users[]" id="user_20" class="subscriber" value="20">
</th>
<td class="username column-username has-row-actions column-primary" data-colname="Username">
<img alt="" src="*imageurl" class="avatar avatar-32 " height="32" width="32" style="height:32px;width:32px">
 <strong><a href="edituserurlinwpadmin">*username*</a></strong><br><div class="row-actions">
 <span class="edit"><a href="*edituserurlinwpadmin*">Edit</a> | </span><span class="delete">
 <a class="submitdelete" href="users.php?action=delete&amp;user=20&amp;_wpnonce=091d3cc8bb">Delete</a> | </span><span class="view">
 <a href="viewuserinwpadmin" aria-label="View posts by *user's name*">View</a> </span></div>
 <button type="button" class="toggle-row"><span class="screen-reader-text">Show more details</span> </button> </td>
 <td class="name column-name" data-colname="Name">*user's firstname & lastname*</td>
 <td class="email column-email" data-colname="Email"><a href="mailto:test@test.com">test@test.com</a></td>
 <td class="role column-role" data-colname="Role">Subscriber</td><td class="posts column-posts num" data-colname="Posts">0</td>
 <td class="heateor_ss_delete_profile_data column-heateor_ss_delete_profile_data" data-colname="Delete Social Profile">
 <a href="javascript:void(0)" title="Click to delete social profile data" alt="Click to delete social profile data" onclick="javascript:heateorSsDeleteSocialProfile(this, 20)">Delete</a></td></tr>

Aucun commentaire:

Enregistrer un commentaire