Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
402 views
in Technique[技术] by (71.8m points)

python - 通过硒选择子CSS元素不起作用(Selecting child css elements through Selenium not working)

I recently started learning python.

(我最近开始学习python。)

I started working on a small automation task for which I've chosen selenium.

(我开始从事一项小型自动化任务,为此我选择了硒。)

The task is, a .NET program will run and a profiler(I'm using Stackify Prefix) will log all the calls as below.

(任务是,将运行.NET程序,探查器(我正在使用Stackify前缀)将记录所有调用,如下所示。) 在此处输入图片说明

I've to loop through all the calls on left hand side and to click each one.

(我必须遍历左侧的所有呼叫,然后单击每个呼叫。)

Which will open a window on the right side with all the data.

(这将在右侧打开一个包含所有数据的窗口。)

Now, I need data from the right hand side under "Request Started".

(现在,我需要“请求已开始”下右侧的数据。)

Beside "Request Started", I've to find the plus symbol, click it and then fetch another div which contains the method name.

(在“请求已启动”旁边,我必须找到加号,单击它,然后获取另一个包含方法名称的div。)

Like below

(像下面) 在此处输入图片说明

While fetching the elements to click the plus symbol, the code is failing.

(在获取元素以单击加号时,代码失败。)

Below is the code.

(下面是代码。)

from selenium import webdriver

    driver = webdriver.Chrome()
    driver.get("http://localhost:2012")
    #colIdentList = driver.find_element_by_class_name('colIdent')
    for result in driver.find_elements_by_class_name('colIdent'):
        result.click()
        #wait = WebDriverWait(driver, 5)
        for plus in driver.find_elements_by_class_name('collapser'):
            plus[0].click()
            for methodDiv in driver.find_elements_by_class_name('willnotrender'):
                value = methodDiv[0].text

    driver.close()

'collapser' is the class for that div which resides under multiple div and td.

('collapser'是该div的类,该类位于多个div和td下。)

I'm pasting XPATH for that component as a reference.

(我正在将该组件的XPATH粘贴为参考。)

But the XPATH is not always same and is different.

(但是XPATH并不总是相同,也有所不同。)

I found two XPATHs for the element.

(我为该元素找到了两个XPATH。)

XPATH : 1. /html/body/div[3]/div/ul/li 2 /div 2 /div[3]/div 2. /html/body/div[3]/div/ul/li 2 /div/div[3]/div

(XPATH:1. / html / body / div [3] / div / ul / li 2 / div 2 / div [3] / div 2. / html / body / div [3] / div / ul / li 2 / div / div [3] / div)

  ask by T.kowshik Yedida translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...