anonymous
anonymous

Reputation: 11

Copy xpath by finding element by tag name

So i was just trying to see if i could automate myself logging into the nike website when i realised that the xpath they use for the input changes every time you reload the page. The only way i managed to find the element was by searching for it by the tag name input . However, when i then try to send the keys to it it gives me the error saying "element not visible". My question is how would i send the keys to it or is there a way of finding the xpath of an element each time i run the code by finding the element by the tag name (input) Here is a copy of my code:

driver.get("https://www.nike.com/gb/en_gb/p/activity/login")
time.sleep(3)
driver.find_element_by_tag_name("input").send_keys("test")

And the website of the form is :https://www.nike.com/gb/en_gb/p/activity/login

Thanks in advance guys :)

Upvotes: 0

Views: 524

Answers (2)

You can also use cssSelector to find elements:

driver.findElement(By.cssSelector("input[name='emailAddress']")).send_keys("abcd");   
driver.findElement(By.cssSelector("input[name='password']")).send_keys("abcd");

Using css-selector is faster than xpath and, in my opinion, it's also easier to declare and customize.

Upvotes: 0

Pradeep hebbar
Pradeep hebbar

Reputation: 2267

I am able to set the email and password with below code

driver.find_element_by_xpath("//input[@type='email']").send_keys("abcd")
driver.find_element_by_xpath("//input[@type='password']").send_keys("abcd")

Upvotes: 2

Related Questions