1st i open the email to get the verification code but when email is open element not found no such element Unable to locate element method xpath selector

+1 vote
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//html/body/table/tbody/tr/td/center/div/table[2]/tbody/tr/td/table/tbody/tr/td/blockquote/b"}
  (Session info: chrome=77.0.3865.90)
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.9.1', revision: '63f7b50', time: '2018-02-07T22:42:28.403Z'
System info: host: 'SR-61', ip: '192.168.33.50', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_202'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 77.0.3865.90, chrome: {chromedriverVersion: 77.0.3865.40 (f484704e052e0..., userDataDir: C:\Users\MUHAMM~1.AWA\AppDa...}, goog:chromeOptions: {debuggerAddress: localhost:59813}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 89e36fcc14bcff009a2470fe607ccff7
*** Element info: {Using=xpath, value=//html/body/table/tbody/tr/td/center/div/table[2]/tbody/tr/td/table/tbody/tr/td/blockquote/b}
Oct 15, 2019 in Selenium by Awais
• 130 points
4,041 views

1 answer to this question.

+1 vote

@Awals, can you please share the code snippet where you are facing this error? Although, these type of errors occur when webdriver isn't able to locate a specific element. So for that you can either your thread.sleep() or implicit_wait or explicit_wait. These methods usually resolves the issue.

answered Oct 15, 2019 by Abha
• 28,140 points

Please check and guide me accrodingly

@Awals, your screenshot isn't clear. Please share the code itself by writing it in comment.
package com.playermatch.loginandregister;

    import java.util.ArrayList;
    import java.util.concurrent.TimeUnit;

    import org.openqa.selenium.By;
    import org.openqa.selenium.Keys;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.JavascriptExecutor;
    import org.openqa.selenium.chrome.ChromeDriver;

    //import org.openqa.selenium.firefox.FirefoxDriver;

    public class test {

        WebDriver driver;
        String myEmail = "";
        String verCode = "";
        
        
        public void invokeBrowser() {
        
        try {
            
            System.setProperty("webdriver.chrome.driver", "D:\\Selenium\\chromedriver\\chromedriver.exe");    
            driver = new ChromeDriver();
            //System.setProperty("webdriver.gecko.driver", "D:\\Selenium\\Firefox\\geckodriver.exe");    
            //driver = new FirefoxDriver();
            driver.manage().deleteAllCookies();
            driver.manage().window().maximize();
            driver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);
            driver.manage().timeouts().pageLoadTimeout(45, TimeUnit.SECONDS);
            
            
            driver.get("https://qa.playermatch.com/register");
            acceptGpr();
            newTab();
            veriCode();
    //        footAgent();

        } catch (Exception e) {
            e.printStackTrace();
        }
        }

        public void acceptGpr() {
            driver.manage().timeouts().pageLoadTimeout(15, TimeUnit.SECONDS);
            driver.findElement(By.xpath("/html/body/div[1]/div/div[1]/div/button[2]")).click();
        }
        
        public void newTab() {
            
            try {
                
//                String SelectLinkNewTab = Keys.chord(Keys.CONTROL,Keys.RETURN);
//                driver.findElement(By.linkText("Login Now")).sendKeys(SelectLinkNewTab);
//                ArrayList<String> tabs = new ArrayList<>(driver.getWindowHandles());
//                driver.switchTo().window(tabs.get(1));
                
                ((JavascriptExecutor)driver).executeScript("window.open('https://www.tempmailaddress.com','_blank');");
                ArrayList<String> tabs = new ArrayList<>(driver.getWindowHandles());
                driver.switchTo().window(tabs.get(1));
                driver.manage().timeouts().pageLoadTimeout(15, TimeUnit.SECONDS);
                String myEmail = driver.findElement(By.className("animace")).getText();
                driver.switchTo().window(tabs.get(0));
                Thread.sleep(3000);
                driver.findElement(By.className("menu_footbaal_ico")).click();
                driver.findElement(By.className("reg_agent_tab")).click();
                driver.findElement(By.id("first_name")).sendKeys("Agent");
                driver.findElement(By.id("email")).sendKeys(myEmail);
                driver.findElement(By.id("password")).sendKeys("qwerty12");
                driver.findElement(By.id("password_confirm")).sendKeys("qwerty12");
                driver.findElement(By.xpath("//*[@id=\"bg_imgg\"]/div[2]/div[2]/div/div[3]/div/form/ul/li[6]/div/div/input")).click();
                driver.findElement(By.xpath("//*[@id=\"bg_imgg\"]/div[2]/div[2]/div/div[3]/div/form/ul/li[7]/button")).click();
                driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL + "t");
                Thread.sleep(3000);
                driver.switchTo().window(tabs.get(1));
                Thread.sleep(10000);
                driver.findElement(By.cssSelector("#schranka > tr:nth-child(1) > td:nth-child(2)")).click();
            } catch (InterruptedException e) {
                
                e.printStackTrace();
            }
        }
        
            public void    veriCode(){
                try {
                    Thread.sleep(10000);
                    String verCode = driver.findElement(By.xpath("//html/body/table/tbody/tr/td/center/div/table[2]/tbody/tr/td/table/tbody/tr/td/blockquote/b")).getText();
                    ArrayList<String> tabs = new ArrayList<>(driver.getWindowHandles());
                    driver.switchTo().window(tabs.get(0));
                    driver.findElement(By.xpath("//*[@id=\"bg_imgg\"]/div[2]/div/div/div[2]/input")).sendKeys(verCode);
                    
                    //String a = "window.open('about:blank','_blank');";
                    //((JavascriptExecutor).driver).executeScript(a);
                } catch (InterruptedException e) {
                    
                    e.printStackTrace();
                }
            }
        
//        public void verficationCode() {
//            try {
//                Thread.sleep(3000);
//                driver
//            }
//        }
        
        
        public static void main(String[] args) {
            
            test twoWay = new test();
            twoWay.invokeBrowser();

        }

    }

Hi Awais,  I think the element which is throwing this error is dynamically loaded and you might need to use explicit_wait in order to wait until the element is displayed or load. Try using following wait command before using find_element method:

WebDriverWait wait = new WebDriverWait(webDriver, timeoutInSeconds);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id<locator>));

or

wait.until(ExpectedConditions.elementToBeClickable(By.id<locator>));

this is the code i used, but still it didn't worked. P.S i there is no "id locator option" in the email.

public void    veriCode(){
                long timeoutInSeconds = 5;
                WebDriver webDriver = null;
                WebDriverWait wait = new WebDriverWait(webDriver, timeoutInSeconds);
                wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".body_text_color > blockquote:nth-child(6) > b:nth-child(1)")));
                String verCode = driver.findElement(By.xpath("//html/body/table/tbody/tr/td/center/div/table[2]/tbody/tr/td/table/tbody/tr/td/blockquote/b")).getText();
                ArrayList<String> tabs = new ArrayList<>(driver.getWindowHandles());
                driver.switchTo().window(tabs.get(0));
                driver.findElement(By.xpath("//*[@id=\"bg_imgg\"]/div[2]/div/div/div[2]/input")).sendKeys(verCode);
            }

this is the exception

Exception in thread "main" java.lang.NullPointerException
    at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:882)
    at org.openqa.selenium.support.ui.FluentWait.<init>(FluentWait.java:96)
    at org.openqa.selenium.support.ui.WebDriverWait.<init>(WebDriverWait.java:72)
    at org.openqa.selenium.support.ui.WebDriverWait.<init>(WebDriverWait.java:46)
    at com.playermatch.loginandregister.test.veriCode(test.java:90)
    at com.playermatch.loginandregister.test.invokeBrowser(test.java:42)
    at com.playermatch.loginandregister.test.main(test.java:109)

@Awais, is your issue resolved? "id locator option" is not an option in your html file, it is the Id of the desired element which you which to locate.  

wait.until(ExpectedConditions.elementToBeClickable(By.id<locator>));
##In above command, in place of locator you use the ID of the element you want to locate.

Related Questions In Selenium

0 votes
0 answers

I am getting no such alert exception in selenium when i tried to run the script

I am getting error after executing the ...READ MORE

Feb 4, 2020 in Selenium by puneeth
• 120 points
3,185 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
13,674 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,143 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
7,221 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,874 views
0 votes
2 answers

I am trying to run the below code but java.lang.Illegalstate Exception is coming

You are facing this error because while ...READ MORE

answered Jun 21, 2019 in Selenium by Abha
• 28,140 points
1,044 views
0 votes
1 answer

i am not able to perform this method in selenium driver.get("google")

Hi Sachin, are you getting any errors ...READ MORE

answered May 15, 2019 in Selenium by Abha
• 28,140 points
1,808 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP