Sorry, just a little change in my question, it was mentioned in Module 14, Part 2 not in Module 15.
Instructor
Ashish Thakur Replied on 27/11/2018
Ok...
is id always starting with 1542691
yes..its always starting with 1542691, but it still not able to find that element when i am using starts-with method.
Instructor
Ashish Thakur Replied on 28/11/2018May be you need to wait for element
No, from wait also its not working.. below is the code-
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class ICICILoan {
/**
* @param args
* @throws InterruptedException
*/
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Gourav\\chromedriver.exe");
WebDriver d=new ChromeDriver();
d.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
d.get("https://loan.icicibank.com/asset-portal/auto-loan/check-eligibility?WT.mc_id=Desk_NLI_ProductPage_ApplyNow");
d.findElement(By.xpath("//*[@id='check-eligibility-page']//div[4]//div//div//form//div[2]//div[1]//div//div//button")).click();
d.findElement(By.xpath("//*[@id='check-eligibility-page']/div[4]/div/div/form/div[2]/div[1]/div/div/div/ul/li[2]/a")).click();
d.findElement(By.xpath("//*[@id='mobileNumber']")).sendKeys("9769116780");
d.findElement(By.xpath("//*[@id='1542687784923']")).click();
Thread.sleep(5000);
d.findElement(By.xpath("//*[starts-with(@id, '1542691')]")).sendKeys("Mumbai");
Thread.sleep(5000);
String s=d.getTitle();
System.out.println(s);
System.out.println();
//1542691071937
}
}
Instructor
Ashish Thakur Replied on 29/11/2018
As I went through your code. It is not working and it seems that you are using browser generated XPath. Please generate your own custom XPath which doesn't contain randomly generated values.
PS numbers are usually random. Try using other attributes.
I tried your code and it is not working because the id is changing in real-time.
Try using the debugger. in real-time and try the XPath you are using in the browser.