硒拉动相同的“ li”标记“ ul”而不是所有人
我的代码目前看起来如此:
the_ul =driver.find_element(By.XPATH,'//ul[@aria-label="Chat content"]')
lis =the_ul.find_elements(By.TAG_NAME,'li')
print(lis)
print("this is len lis: ",len(lis))
for i in lis:
txt=i.find_element(By.XPATH,'//div[@class="ui-chat__messageheader"]/time').get_attribute('title')
print("TXT: ",txt)
对我的理解,“ lis”应该在“ the_ul”中具有每个独特的“ li”。但是,打印语句如下:
[<selenium.webdriver.remote.webelement.WebElement (session="d8381099435e4dd6d9b64c380a16325f", element="e1b79379-bb3d-4a7a-aa83-16d9b65be830")>, <selenium.webdriver.remote.webelement.WebElement (session="d8381099435e4dd6d9b64c380a16325f", element="671d3f30-f88d-45c1-b478-a343833b6334")>, <selenium.webdriver.remote.webelement.WebElement (session="d8381099435e4dd6d9b64c380a16325f", element="dab6680b-fcf7-410f-9b08-71af744bc6c8")>]
this is len lis: 3
TXT: June 13, 2022 6:35 PM
TXT: June 13, 2022 6:35 PM
TXT: June 13, 2022 6:35 PM
“ lis”中的所有元素似乎与打印语句相同的输出的值完全相同。我可以在给定的“ li”标签中确认所有值都应不同。
我不确定为什么会这样,我尝试更改lis = the_ul.find_elements(by.tag_name,'li')
to lis = the_ul.find_elements(by.tag_name) ,'// li')
,但仍然没有解决问题。也许我没有正确迭代这些元素?但是我似乎找不到这个问题。
My code currently looks as such:
the_ul =driver.find_element(By.XPATH,'//ul[@aria-label="Chat content"]')
lis =the_ul.find_elements(By.TAG_NAME,'li')
print(lis)
print("this is len lis: ",len(lis))
for i in lis:
txt=i.find_element(By.XPATH,'//div[@class="ui-chat__messageheader"]/time').get_attribute('title')
print("TXT: ",txt)
to my understanding 'lis' should have every unique 'li' within 'the_ul'. However, the print statements are as follows:
[<selenium.webdriver.remote.webelement.WebElement (session="d8381099435e4dd6d9b64c380a16325f", element="e1b79379-bb3d-4a7a-aa83-16d9b65be830")>, <selenium.webdriver.remote.webelement.WebElement (session="d8381099435e4dd6d9b64c380a16325f", element="671d3f30-f88d-45c1-b478-a343833b6334")>, <selenium.webdriver.remote.webelement.WebElement (session="d8381099435e4dd6d9b64c380a16325f", element="dab6680b-fcf7-410f-9b08-71af744bc6c8")>]
this is len lis: 3
TXT: June 13, 2022 6:35 PM
TXT: June 13, 2022 6:35 PM
TXT: June 13, 2022 6:35 PM
It seems like all the elements in the 'lis' are the same as such the print statement outputs the exact same value. I can confirm all the values should be different within the given 'li' tags.
I am unsure of why this seems to be the case, I had tried changing lis =the_ul.find_elements(By.TAG_NAME,'li')
to lis =the_ul.find_elements(By.TAG_NAME,'//li')
but still, it does not fix the issue. Perhaps I am not iterating over the elements correctly? But I can't seem to find the issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于元素的X path量如何工作,可能需要是以下内容。需要.//。
Might need to be the following due to how xpathing from an element works. Which needs .// .