Python selenium:我需要在Autotask.net的元素中查找元素的帮助
我试图在自动任务网页上找到一个元素,以便与之交互: 我使用以下代码在元素中搜索:Python selenium:我需要在Autotask.net的元素中查找元素的帮助,python,selenium,Python,Selenium,我试图在自动任务网页上找到一个元素,以便与之交互: 我使用以下代码在元素中搜索: header=driver.find_element_by_css_selector('html') body=header.find_element_by_css_selector('body') body1=body.find_element_by_css_selector('#WorkspaceContainer') body1.find_element_by_css_selector('#Workspace
header=driver.find_element_by_css_selector('html')
body=header.find_element_by_css_selector('body')
body1=body.find_element_by_css_selector('#WorkspaceContainer')
body1.find_element_by_css_selector('#WorkspaceContainer > div:nth-child(1)')
body2=body1.find_element_by_css_selector('#WorkspaceContainer > div:nth-child(1)')
body2.find_element_by_css_selector('#PageContainer')
body3=body2.find_element_by_css_selector('#PageContainer')
body3.find_element_by_css_selector('#PageContainerFrame')
body4=body3.find_element_by_css_selector('#PageContainerFrame')
body4.find_element_by_css_selector('html')
body5=body4.find_element_by_css_selector('html')
body5.find_element_by_css_selector('body')
body6=body5.find_element_by_css_selector('body')
我似乎成功地浏览了它们,但在这一行失败了,只有一个例外:
body4.find_element_by_css_selector('html')
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: {"method":"css selector","selector":"html"}
我曾通过pyautogui模块使用鼠标移动和单击与站点交互,但有人告诉我,与元素本身交互更可靠。有人能帮忙吗?似乎您正在尝试处理
iframe
中的元素
要执行此操作,首先需要切换到此帧:
body3.switch_to_frame('PageContainerFrame')
body3.find_element_by_css_selector('html')
另外,如果您只需要处理一个元素,那么最好使用relative
XPath
直接指向它,而不是从父元素到子元素的连续步进 似乎您正在尝试处理iframe
中的元素
要执行此操作,首先需要切换到此帧:
body3.switch_to_frame('PageContainerFrame')
body3.find_element_by_css_selector('html')
另外,如果您只需要处理一个元素,那么最好使用relative
XPath
直接指向它,而不是从父元素到子元素的连续步进 是否有要在其中查找元素的iframe?是否有要在其中查找元素的iframe?我的xpath是id('Table6')/x:tbody/x:tr/x:td[3]/x:a要处理哪个元素?它是一个按钮还是一个链接?描述它,以便我可以在页面上搜索链接文本是一个票号(即T20161010.0100),它链接到票号。最后,我想用ActionChains来点击它。单击后,它将打开另一个包含票证信息的窗口。您应该使用以下行:driver.switch_to_frame('PageContainerFrame')
(假设PageContainerFrame
是包含目标链接的iframe
的id
)driver)。单击()
MyXPath是id('Table6')/x:tbody/x:tr/x:td[3]/x:a要处理哪个元素?它是一个按钮还是一个链接?描述它,以便我可以在页面上搜索链接文本是一个票号(即T20161010.0100),它链接到票号。最后,我想用ActionChains来点击它。单击后,它将打开另一个包含票证信息的窗口。您应该使用以下行:driver.switch_to_frame('PageContainerFrame')
(假设PageContainerFrame
是包含目标链接的iframe
的id
)driver)。单击()