how to find By from WebElement

Solved 1 Answers 51 Views Selenium
0 1
I have a scenation where I need to print which element is being worked on on console. I am identifying element and passing it to one function where all clicking and waiting for an element happens. I am currently printing element.toString() but its giving me lots of informations. I need just By to be displayed on screen? Have anyone tried this?

1 Answer

Best answer
You may extend your RemoteWebDriver class as below.

import java.io.File;
import java.io.FileNotFoundException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import java.util.Set;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.CommandExecutor;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.Response;

public class xRemoteWebDriver extends RemoteWebDriver {
    private boolean debug = true;

    public xRemoteWebDriver(CommandExecutor executor,
            Capabilities desiredCapabilities, Log log) {
        super(executor, desiredCapabilities);

    public xRemoteWebDriver(Capabilities desiredCapabilities, Log log) {

    public xRemoteWebDriver(URL remoteAddress,
            Capabilities desiredCapabilities, Log log) {
        super(remoteAddress, desiredCapabilities);

    protected Response  execute(String driverCommand, Map<String, ?> parameters){
        printCommands(driverCommand, parameters);
        return super.execute(driverCommand, parameters);
    private void printCommands(String driverCommand, Map<String, ?> parameters){
                Set<String> keys = parameters.keySet();
                for(String key : keys)
                    System.out.print("\t"+key + "\t" +parameters.get(key));
            }catch(Exception ignore){
    public boolean isDebug() {
        return debug;

    public void setDebug(boolean debug) {
        this.debug = debug;

answered by
selected by

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

We have resolved 1.2k+ Software Testing queries!

Top Contributors