简体   繁体   English

我无法迭代(定位)从 selenium python 提交的此输入,每次 id 更改,并且完整的 Xpath 也不起作用

[英]I am unable to iterate(locate) this input filed from selenium python, every time id changed, and full Xpath is also not working

Hy all, I am unable to iterate this input filed from selenium python, every time id changed, and full Xpath is also not working.大家好,我无法迭代从 selenium python 提交的此输入,每次 id 更改,并且完整的 Xpath 也不起作用。 URL: https://support.google.com/blogger/answer/3091837 URL: https://support.google.com/blogger/answer/3091837

i tried already: -我已经试过了:-

driver.find_element_by_name("blog_URL").click()
driver.find_element_by_xpath('//*[@id="render_api158171433--blog_URL"]').click()
driver.find_element_by_xpath("/html/body/div[8]/div/section/div/div[1]/article/section/div/div[2]/div[1]/form/div[1]/input").click()
driver.find_element_by_id('render_api535892960--blog_URL')[2].click()

Your <input> has an slippery id but its name seems to be unique name="blog_URL" , so you could use find_element_by_name你的<input>有一个滑的 id 但它的名字似乎是唯一的name="blog_URL" ,所以你可以使用find_element_by_name

Anyway when an id or class changes every time, findById or xpath with exact values does not help.无论如何,当 id 或 class 每次都更改时,具有精确值的 findById 或 xpath 无济于事。

You can try other approaches such as: looking for neighbors, parents, children,sibling, etc., which can be located and then navigate until to find your slippery <input> .您可以尝试其他方法,例如:寻找邻居,父母,孩子,兄弟姐妹等,可以定位然后导航直到找到您的滑<input> This will be a little expensive!!这会有点贵!!

Samples according to your html:根据您的 html 的样品:

form has an unique id表单有一个唯一的 id

  • locate form by id = harassment按 id 定位表格 = 骚扰
parentElement = driver.find_element_by_id("myFormId")
  • get all child elements获取所有子元素
childElementsOfForm = parentElement.find_elements_by_xpath(".//*")
  • Iterate elements and get the second and perform a new find inside of this element.迭代元素并获取第二个元素并在此元素内执行新的查找。 We can see that our <input> in another child of it.我们可以看到我们的<input>在它的另一个孩子中。

search all inputs in form搜索表单中的所有输入

parentElement = driver.find_element_by_id("myFormId")
elementList = parentElement.find_elements_by_tag_name("input")

Iterate them and search an input whose id starts with render_api迭代它们并搜索 id 以render_api开头的输入

Locating elements using advanced CSS selectors使用高级 CSS 选择器定位元素

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 每次在硒python 2.7 chrome中更改xpath的id - id of xpath is getting changed every time in selenium python 2.7 chrome 无法在 python Z8E00596AD8DE2213FF8F8D8478D5362ZC 中找到具有 xpath 和 id 的 iframe - unable to locate iframe with xpath and id in python selenium 无法定位 id python selenium - Unable to locate id python selenium Python Selenium:无法通过Xpath定位元素 - Python Selenium: Unable to locate the element by Xpath 无法使用 xpath 使用 python 和 selenium 定位元素 - Unable to locate element with xpath using python and selenium 无法通过 xpath 使用 Selenium 和 Python 定位元素 - Unable to locate element by xpath using Selenium with Python 无法定位 xpath 元素 - Selenium、Python、Chromedriver - Unable to locate xpath element - Selenium, Python, Chromedriver selenium 驱动程序,button=driver.find_element_by_xpath(“//input[@id='alpha']”) 消息:没有这样的元素:无法定位元素 - selenium driver, button=driver.find_element_by_xpath(“//input[@id='alpha']”) Message: no such element: Unable to locate element 无法使用 Selenium Python 找到具有 id、class_name 和 xpath 的元素 - Unable to locate element with id, class_name and xpath using Selenium Python Python: Selenium 没有这样的元素: 无法定位元素: {“method”:“xpath”,“selector”:“//button[@data-id=1]”} - Python: Selenium no such element: Unable to locate element: {“method”:“xpath”,“selector”:“//button[@data-id=1]”}
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM