如何在iframe中使用XPATH? [英] How take XPATH inside a iframe?

查看:2276
本文介绍了如何在iframe中使用XPATH?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在名为gadget_6的iframe中获取XPATH

Im trying to get the XPATH inside a iframe called "gadget_6"

我需要选择的xpath DIV。使用selenium我做:

i need the xpath of select div. Using selenium i do:

self.change_frame('__gadget_6') #Change to the correct iframe

之后,我尝试这样做:

self.selec_orgvdc = self.driver.find_element(By.XPATH,'/html/body/div[5]/div/div/div/table/tbody/tr/td/div')

以后做:

self.selec_orgvdc.click

但我收到错误:

InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression /html/body/div[5]/div/div/div/table/tbody/tr/td/div because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '/html/body/div[5]/div/div/div/table/tbody/tr/td/div' is not a valid XPath expression.

有人可以帮助我吗?

新修改:

self.change_frame('__gadget_6')
time.sleep(4)
self.logger.info("Buscando orgvdc")
#self.selec_orgvdc = self.driver.find_element(By.CSS_SELECTOR,'div.GN4Y2ATIMD table div.gwt-Label')
self.selec_orgvdc = self.driver.find_element(By.XPATH,'//div[5]/div/div/div/table/tbody/tr/td/div')
self.logger.info("Encontrado!")


推荐答案

您好先在iframe中使用xpath首先必须抛弃你的驱动程序实例ti iframe然后只能执行任何操作

Hi to work with xpath inside iframe first you have to sitch your driver instance ti that iframe then only you can perform any action

1.To switch to an iframe plz do it like : driver.switchTo().frame("selfservice");

同时查看您的源代码我可以清楚地看到有2(2)个i帧

Also looking at your source code i can clearly see there is 2 (two) i frames

1.iframe id = __gadget_6
2.iframe id = selfservice

1.iframe id = __gadget_6 2.iframe id = selfservice

因此我可以猜到为什么它不是在你的情况下工作因为你正在切换到错误的i帧

hence i can guess why its not working in your case cause you are switching to a wrong i frame

现在试试这个 xpath // * [@ class ='GN4Y2ATIMD'] / div / div / div / table / tbody / tr / td / div 执行点击这肯定会有效。

now try this xpath //*[@class='GN4Y2ATIMD']/div/div/div/table/tbody/tr/td/div to perform click this will surely work.

这篇关于如何在iframe中使用XPATH?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆