问题描述:

Using Selenium Python:

I have an overlay form which has an email text form. I am using the following code to get to overlay form (works fine) and then recognize the email address text box, but is not filling in the value that I desire to fill in the email text box. here is the code I am using.

browser.switch_to_frame('loginModel')

browser.find_element_by_xpath(

"//*[@id='loginboxif']h1").send_keys('[email protected]')

Which is giving the error

 line 10, in <module>

browser.find_element_by_xpath("//*[@id='loginboxif']/h1").send_keys('[email protected]')

File "C:\Python27\lib\selenium\webdriver\remote\webdriver.py", line 221, in find_element_by_xpath

return self.find_element(by=By.XPATH, value=xpath)

网友答案:

I dont find 'h1' in the html you posted. Then why are you referring that in xpath.

You could simply do the following:

browser.find_element_by_id('dwfrm_login_username').send_keys('[email protected]')

or

browser.find_element_by_name('dwfrm_login_username).send_keys('[email protected]')

Hope that helps !

网友答案:
//*[@id='loginboxif']h1

is not a valid XPath query. This is your problem. Depending on what you are trying to do, you may want:

//*[@id='loginboxif']//h1

Similarly:

find_element_by_class_name('input-text email required')

Compound class names are not allowed.

相关阅读:
Top