selenium - Webdriver - Unable to locate element (Java) -


i'm new in selenium , webdriver. have html:

<input id="undefined-undefined-jobsubject-5546" type="text" value="" data-test="testing-job-subject" style="padding: 0px; position: relative; width: 100%; border: medium none; outline: medium none; background-color: transparent; color: rgb(255, 255, 255); cursor: initial; font: inherit; height: 100%; box-sizing: border-box; margin-top: 14px;"/>

and have code:

driver.findelement(by.xpath("//input[@data-test='testing-job-subject']")); 

but error is:

org.openqa.selenium.nosuchelementexception: unable locate element: //input[@data-test='testing-job-subject']

i tried this:

driver.findelement(by.xpath("//*[starts-with(@id,'undefined-undefined-jobsubject')]")); 

because number in id generated, can't take by.id(....), same error. , yes,i have in code timeouts,so element on page.

where problem? thanks

if getting nosuchelementexception provided exception, there may following reasons :-

  • may when going find element, not present on dom, should implement webdriverwait wait until element visible below :-

    webdriverwait wait = new webdriverwait(driver, 10); webelement el = wait.until(expectedconditions.visibilityofelementlocated(by.cssselector("input[data-test='testing-job-subject']"))); 
  • may element inside frame or iframe. if is, need switch frame or iframe before finding element below :-

    webdriverwait wait = new webdriverwait(driver, 10);  //find frame or iframe , switch wait.until(expectedconditions.frametobeavailableandswitchtoit("your frame id or name"));  //now find element  webelement el = wait.until(expectedconditions.visibilityofelementlocated(by.cssselector("input[data-test='testing-job-subject']")));  //once stuff done frame need switch default driver.switchto().defaultcontent(); 

Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -