How to type in the search textbox whose xpath is not static

65 views
Skip to first unread message

AYUSH GUPTA

unread,
Apr 10, 2014, 8:42:38 AM4/10/14
to seleniu...@googlegroups.com
Hi Guys,

I am trying to type in a search box whose xpath is not fixed and changes every time I click.
Currently xpath is './/*[@id='u_jsonp_11_1p']/span/input' and last time it was './/*[@id='u_jsonp_9_1p']/span/input' 

I think the best way is to use href to locate this xpath but I am not sure how to do that.
Please let me know if anyone have any idea.

Thanks
Ayush Gupta

Vikas Gahlaut

unread,
Apr 10, 2014, 8:45:08 AM4/10/14
to seleniu...@googlegroups.com

In this case absolute xpath(html based) will be same..use that or go for css..

Best regards,
Vikas Gahlaut

--
You received this message because you are subscribed to the Google Groups "Selenium Experts" group.
Visit this group at http://groups.google.com/group/seleniumexperts.

Rakesh Sharma

unread,
Apr 10, 2014, 9:03:53 AM4/10/14
to seleniumexperts

You may use //input[contains(@id,'u_jasonp')]

--

AYUSH GUPTA

unread,
Apr 10, 2014, 11:18:10 AM4/10/14
to seleniu...@googlegroups.com
Hi, I am trying to use abosolute xpath as below:
selenium.type("html/body/div[1]/div[2]/div[1]/div/div[2]/div[2]/div[2]/div/div/div/div[2]/div/div[1]/div[2]/div[2]/div/div/div/span/span/input","r");
but I am getting below error :
Exception in thread "main" com.thoughtworks.selenium.SeleniumException: ERROR: Element html/body/div[1]/div[2]/div[1]/div/div[2]/div[2]/div[2]/div/div/div/div[2]/div/div[1]/div[2]/div[2]/div/div/div/span/span/input not found
at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:112)
at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:106)
at com.thoughtworks.selenium.DefaultSelenium.type(DefaultSelenium.java:317)
at sel_practise1.main(sel_practise1.java:27)

Thanks
Ayush

AYUSH GUPTA

unread,
Apr 10, 2014, 12:31:05 PM4/10/14
to seleniu...@googlegroups.com
Hi...got my mistake. Was missing 'xpath='.

Thanks
Ayush

shuklasa...@gmail.com

unread,
Apr 11, 2014, 3:34:22 AM4/11/14
to seleniu...@googlegroups.com, AYUSH GUPTA
You can use cssSelector as
                         [id*='u_jsonp']
                         or
                         [id^='u_jsonp']

AYUSH GUPTA

unread,
Apr 11, 2014, 3:41:33 AM4/11/14
to seleniu...@googlegroups.com
It worked out guys..Thanks

Regards
Ayush
On Friday, 11 April 2014, 13:06, "shuklasa...@gmail.com" <shuklasa...@gmail.com> wrote:
You can use cssSelector as
                         [id*='u_jsonp']
                         or
                         [id^='u_jsonp']
        

On Thursday, April 10, 2014 6:12:38 PM UTC+5:30, ayush gupta wrote:
Hi Guys,

I am trying to type in a search box whose xpath is not fixed and changes every time I click.
Currently xpath is './/*[@id='u_jsonp_11_1p']/ span/input' and last time it was './/*[@id='u_jsonp_9_1p']/ span/input' 

I think the best way is to use href to locate this xpath but I am not sure how to do that.
Please let me know if anyone have any idea.

Thanks
Ayush Gupta
--

Vikas Gaur

unread,
Apr 11, 2014, 1:59:47 AM4/11/14
to seleniu...@googlegroups.com
You can use the below...

static WebDriver driver = new FirefoxDriver();
driver.findElement(By.XPATH(".//*[@id='isCartBtn_btn']")).sendKeys("XYZ");


--
You received this message because you are subscribed to the Google Groups "Selenium Experts" group.
Visit this group at http://groups.google.com/group/seleniumexperts.



--
--
Thanks & Regards

Vikas Gaur
Sapient Noida
Mobile: +91-9350725728
http://qainfotesting.blogspot.com
You love life, life will love you back.
Reply all
Reply to author
Forward
0 new messages