0

I am trying to fill out a form for states where I would select one at the bottom Oregon. From https://www.adidas.com/us/delivery-start. New to coding thank you!

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select


state = driver.find_element_by_xpath('//*[@id="dwfrm_delivery"]/div[2]/div[2]/div/fieldset/div/div[1]/div[6]/div[1]/div/div/a/span')
stateselect = state.select_by_visible_test("Oregon")

This is the error I am getting

AttributeError: 'WebElement' object has no attribute 'select_by_visible_test'.

And with

state = driver.find_element_by_xpath('//*[@id="dwfrm_delivery"]/div[2]/div[2]/div/fieldset/div/div[1]/div[6]/div[1]/div/div/a/span')
stateselect = state.send_keys("Oregon")

I get the following :

error:WebDriverException: Message: unknown error: cannot focus element

Please help me understand the error for both cases to further my understanding. And point me in the right direction.

2
  • The best way to help you is to help you help yourself. What have you done to try to solve your problem? Lots of other people have encountered the "cannot focus element" error. Have you tried any of the things that worked for them? Commented Mar 30, 2017 at 20:51
  • See also: sqa.stackexchange.com/a/2258/24544 Commented Mar 30, 2017 at 20:58

1 Answer 1

1

When you're copying code always double-check you've copied it correctly.

select_by_visible_test should be select_by_visible_text

But that won't work because you're not using the select class. Before using stateselect you need:

stateselect = Select(state)

And then you can do:

stateselect.select_by_visible_text("Oregon")

You should also check the official documentation. In this case, the documentation for the python selenium api for WebElement and Select. You can almost always find the documentation by searching for, e.g., "python selenium select"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.