How to find XPath in Chrome Browser for Selenium WebDriver

40
Rate this post



This video will guide you How to find XPath in Chrome Browser for Selenium WebDriver without any add-on.

If you are new to xpath and CSS then kindly visit below links

-~-~~-~~~-~~-~-
Please watch: “How To Create Maven build For Selenium Framework”

-~-~~-~~~-~~-~-

Tag: xpath chrome, How to find XPath in Chrome Browser for Selenium WebDriver, Selenium Webdriver Tutorial, Chrome XPath in Selenium, Find Xpath in Selenium Webdriver, Dynamic XPath in Selenium, Xpath Tutorials

Xem thêm: https://thuthuat789.com/category/review

Nguồn: https://thuthuat789.com

40 Comments

  1. I am having trouble in locating a live chat bot….So I inspect and I am not able to find any locator so that I can use that in scripting ..How I can sovlve this?

    Reply
  2. package demo;

    import org.openqa.selenium.chrome.ChromeDriver;

    import org.openqa.selenium.support.ui.Select;

    import org.openqa.selenium.By;

    import org.openqa.selenium.WebDriver;

    import org.openqa.selenium.WebElement;

    public class Firstcode {

    public static void main(String[] args) throws InterruptedException {

    // TODO Auto-generated method stub

    System.setProperty("webdriver.chrome.driver", "C:\browsers\chromedriver.exe");

    ChromeDriver driver = new ChromeDriver();

    driver.get("https://login.salesforce.com");

    Thread.sleep(3000);

    System.out.println(driver.getTitle());

    /*driver.findElement(By.id("username")).sendKeys("12345890");

    driver.findElement(By.id("password")).sendKeys("21313");

    driver.findElement(By.id("Login")).click();*/

    //forgot password code

    /*System.out.println("driver.findElement(By.id('error'))");

    driver.findElement(By.id("forgot_password_link")).click();

    driver.findElement(By.id("un")).sendKeys("1213313");

    driver.findElement(By.id("continue")).click();

    driver.findElement(By.id("un")).sendKeys("12345890");

    driver.findElement(By.id("continue")).click();

    driver.findElement(By.linkText("Cancel")).click(); */

    /* use customer domain

    driver.findElement(By.id("mydomainLink")).click();

    driver.findElement(By.id("mydomain")).sendKeys("1233");

    //driver.findElement(By.id("mydomainContinue")).click();

    driver.findElement(By.id("hint_back_domain")).click(); */

    //try for free

    Thread.sleep(10000);

    driver.findElement(By.id("signup_link")).click();

    Thread.sleep(3000);

    driver.findElement(By.name("UserFirstName")).sendKeys("user01");

    Thread.sleep(3000);

    driver.findElement(By.name("UserLastName")).sendKeys("last01");

    Thread.sleep(3000);

    driver.findElement(By.name("UserTitle")).sendKeys("BE01");

    Thread.sleep(3000);

    driver.findElement(By.name("UserEmail")).sendKeys("[email protected]");

    driver.findElement(By.name("UserPhone")).sendKeys("9554674789");

    Thread.sleep(3000);

    driver.findElement(By.name("CompanyName")).sendKeys("actouch.com");

    Thread.sleep(3000);

    Select s= new Select(driver.findElement(By.name("CompanyEmployees")));

    Thread.sleep(1000);

    s.selectByIndex(2);

    Thread.sleep(1000);

    driver.findElement(By.xpath("//div[@class='msaCheckbox checkboxInput section']//div//div//div[1]")).click();

    Thread.sleep(1000);

    driver.close();

    }

    }

    when i am practices selenium code for salesforce website i clicked try free button manual then next page will open which have some fields but when i am run the selenium code then next page opening will different fields .
    can any help why it is opening different fields.
    2) even when we click check box i get error in console as 👀 no such element: Unable to locate element .
    3) when I am using drop down with s.selectByValue("1 – 20 employees"); then i am getting error in console as 😢Cannot locate option with value: 1 – 20 employees

    Reply
  3. Hi Mukesh, Hope you are doing good! , How to check xpath/css selectors using chrome/FF for the node.js type of applications? like I have been working web applications implemented using polymer components(i.e it has too many complex nested #shadow-root (open) tags ) To find one input box will be having mini 20 shadow-root in b/w from root main tag to inner child tag.
    Can you suggest Protractor with jasmine framework will support and report tools ?

    Reply
  4. If you could have the windows little adjusted, so that the scrolling red line of youtube video will not disturb the viewer`s ability to understand the xpath coding you are doing in future. In this video, example at 2:35 the xpath code you`ve written is just coming on the youtube`s red scrolling line !!

    Reply
  5. Hi Mukesh,
    I am new in Selenium and want to learn from very beginning. After a bit more research in Goggle and YouTube, I found your channel. This is really awesome. Only one problem I am facing that the videos do not have any serial no. or they are not in series. Could you please guide me that from which video I should start and how I can move forward ? Thanks in advance.

    Reply
  6. I'm trying to do your exercise and I have some issues…..
    I have a button in a modal, but when I try to close it with this function

    driver.findElement(By.xpath("//button[@type='button']")).click();

    I don't have the correct result, can you help me please?
    These are my options that I tried…..
    //driver.close();
    //WebDriverWait wait = new WebDriverWait(driver, 3);
    driver.findElement(By.xpath("//button[@type='submit']")).click();
    //driver.findElement(By.xpath("//*[@class='bootbox-close-button close']")).click();
    //driver.findElement(By.className("//*[@class='bootbox-close-button']")).click();
    //driver.findElement(By.xpath("/html/body/div[2]/div/div/div[1]/@type='button']")).click();
    //driver.findElement(By.xpath("/html/body/div[2]/div/div/div[1]/button")).click();

    //driver.switchTo().activeElement().sendKeys(Keys.ENTER);
    //driver.findElement(By.xpath("//button[starts-with(@type,'button')]")).click();
    //driver.findElement(By.xpath("/html/body/div[2]/div/div/div[1]/button")).click();
    //WebElement element = driver.findElement(By.xpath("//*[@test-type='button']"));
    //driver.findElement(By.xpath("//button[contains(@type,'button')]")).click();
    //driver.elementToBeClickable(By.xpath("type=button"))).click();
    //WebDriverWait wait = new WebDriverWait(driver, 5);
    //wait.until(ExpectedConditions.elementToBeClickable(By.xpath("button#button"))).click();
    //Alert alert = new WebDriverWait(driver, 20).until(ExpectedConditions.alertIsPresent());
    //alert.accept();
    //WebDriverWait wait = new WebDriverWait(driver, 10);
    //Now wait until this dialog close button visible and clickable then click
    //wait.until(ExpectedConditions.elementToBeClickable(By.xpath("/html/body/div[2]/div/div/div[1]/button"))).click();
    //WebElement xButton = driver.findElement(By.cssSelector(".bootbox-close-button close"));
    //JavascriptExecutor js = (JavascriptExecutor) driver;
    //js.executeScript("arguments[0].click()", xButton);
    //cancel_button = browser.div("@class= modal-footer").button(:class => "btn btn-danger");
    //cancel_button.when_present.click();
    // String winHandleBefore =
    // driver.getWindowHandle();
    // driver.findElement(By.xpath("/html/body/div[2]/div/div/div[1]/button")).click();
    // Xpath of register Button
    // Set handles = (Set) driver.getWindowHandles();
    //WebDriverWait wait = new WebDriverWait(driver, 10);

    //Click on read more button to open this dialog
    //wait.until(ExpectedConditions.elementToBeClickable(By.partialLinkText("x"))).click();

    //Now wait until this dialog close button visible and clickable then click
    //wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.bootbox-close-button close"))).click();
    //driver.findElement(By.xpath("/html/body/div[2]/div/div/div[1]/button[contains(@class,'bootbox-close-button close')]")).click();
    //driver.findElement(By.xpath("//div[@tabindex='-1']//button[@type='button']")).click();
    //driver.findElement(By.className("@class= bootbox-close-button close")).click();
    //driver.findElement(By.className("//div[@class= 'bootbox modal fade in']/div[@class= 'modal-dialog']/div[@class= 'modal-content']/div[@class= 'modal-header']/button[@class= 'bootbox-close-button close']")).click();
    //driver.findElement(By.className("//button[@class= 'bootbox-close-button close']")).click();
    //driver.findElement(By.className("//button[starts-with(@class,'bootbox-close-button close')]")).click();
    /*if(driver.switchTo().alert() != null)
    {
    Alert alert = driver.switchTo().alert();
    String alertText = alert.getText();
    alert.dismiss(); // alert.accept();
    }*/
    //WebDriverWait wait = new WebDriverWait(driver, 20);
    //wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("bootbox-close-button close"))).click();
    //driver.findElement(By.cssSelector("body > div.bootbox.modal.fade.in > div > div > div.modal-header > button")).sendKeys(Keys.chord(Keys.ALT, Keys.F4));
    //driver.findElement(By.cssSelector("body > div.bootbox.modal.fade.in > div > div > div.modal-header > button")).click();
    //driver.findElement(By.className("bootbox-close-button close")).click();
    //WebDriver driver=new FirefoxDriver();
    //driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    //driver.findElement(By.className("bootbox-close-button close")).click();
    // Alert alert = driver.switchTo().alert();
    // System.out.println(alert.getText());
    //try {
    // Thread.sleep(5000);
    // } catch (InterruptedException e) {
    // e.printStackTrace();
    // }
    //alert.dismiss();

    Reply
  7. sir please i want to give a little project for selenium please make this project video and share on you tube its helpful for everyone
    in this we use webdriver and testng and maven etc

    Reply
  8. sir please share about "git hub" its reaaly very important .
    how to install and how to work on this, how to check repository all about this pls as soon as possible its urgent

    Reply
  9. Hi Mukesh,

    Actually I have a doubt, Suppose that I am testing or running the script for Facebook, So when i would like to signup or register for the new account then to insert any text in the text box we need locate the element by ID/className and etc.

    So, could u tell me that the Id for any of the textbox gets changed frequently while inspecting?

    Reply
  10. Hi Mukesh sir, I have just started learning selenium from your videos, I am not able to post my query on your site.please help me with that. I am stuck with two words that is selenium driver and testNg, how this two differ from each other or are these interlinked.

    Reply
  11. Hello, One of the interview that was asked to me last week was… Was there any Data Limitation in your application? For ex: I can only enter 20 characters in my text box… If so then how did you handle that… I couldnt answer this because I havn't come across such situation… Can I get an answer for this?

    This question was asked by Client in Client round at JP morgan

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *