Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
试图通过selenium python选择输入框,但';id';在中,每次重新加载页面时元素都会发生更改_Python_Selenium_Xpath_Css Selectors_Webdriverwait - Fatal编程技术网

试图通过selenium python选择输入框,但';id';在中,每次重新加载页面时元素都会发生更改

试图通过selenium python选择输入框,但';id';在中,每次重新加载页面时元素都会发生更改,python,selenium,xpath,css-selectors,webdriverwait,Python,Selenium,Xpath,Css Selectors,Webdriverwait,HTML: XPATH: /html/body/div[2]/div[3]/div[5]/form/div[1]/input 有任何帮助吗?要向电子邮件地址字段发送字符序列,您可以使用以下任一选项: 使用css\u选择器: //*[@id="4a463943-7f58-42ea-9317-ba9f9518811e" except the ID changes. 使用xpath: driver.find_element(By.CSS_SELECTOR, "i

HTML:

XPATH:

/html/body/div[2]/div[3]/div[5]/form/div[1]/input
有任何帮助吗?

要向电子邮件地址字段发送字符序列,您可以使用以下任一选项:

  • 使用
    css\u选择器

    //*[@id="4a463943-7f58-42ea-9317-ba9f9518811e" except the ID changes. 
    
  • 使用
    xpath

    driver.find_element(By.CSS_SELECTOR, "input[name='emailAddress'][data-componentname='emailAddress']").send_keys("sebtheoo@stackoverflow.com")
    
所需的元素是动态元素,因此理想情况下,要将字符序列发送到需要为导出的元素,可以使用以下任一选项:

  • 使用
    CSS\u选择器

    driver.find_element(By.XPATH, "//input[@name='emailAddress' and @data-componentname='emailAddress']").send_keys("sebtheoo@stackoverflow.com")
    
  • 使用
    XPATH

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[name='emailAddress'][data-componentname='emailAddress']"))).send_keys("sebtheoo@stackoverflow.com")
    
  • 注意:您必须添加以下导入:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@name='emailAddress' and @data-componentname='emailAddress']"))).send_keys("sebtheoo@stackoverflow.com")
    

尝试按标记名选择元素

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
或 因为它有一个name属性,所以您也可以尝试

input_box = driver.find_elements_by_tag_name('tag_name_of_input_box')
或者,因为它还有一个占位符,所以即使您可以将xpath与占位符结合起来

input_box = driver.find_element_by_name('emailAddress')

你需要检查没有改变的标签。例如,在这两个数据中,名称不变。因此,你可以继续前进

要使用名称标记访问元素,请尝试以下操作:


非常感谢,这真的很好。我怎样才能访问一个元素,因为它包含在感谢中
input_box = driver.find_elements_by_tag_name('tag_name_of_input_box')
input_box = driver.find_element_by_name('emailAddress')
input_box = driver.find_element_by_xpath('"//input[@placeholder='Email address']"')
driver.findElement(By.name("emailAddress"));