Issue
Using python selenium i am trying to pull information from li class below is the code which i have tried but getting error:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element:
{"method":"xpath","selector":"//ul[@class='oas_columnsWrapper']//following::li[2]"}
I want to print:- 218543-Not Applicable+OA
Below is the code which I have tried but no luck.
Please help!
print(browser.find_element(By.XPATH,"//ul[@class='oas_columnsWrapper']//following::li[2]").Attribute("innerHTML"))
My html code:
<ul class="omniAds__oas_columnsWrapper">
<li class="omniAds__oas_columns">1.</li>
<li class="omniAds__oas_columns">218543-Not Applicable+OA</li>
<li class="omniAds__oas_columns"></li>
<li class="omniAds__oas_columns">23-11-2021</li>
<li class="omniAds__oas_columns">19,452</li>
<li class="omniAds__oas_columns">546</li>
<li class="omniAds__oas_columns">3%</li>
<li class="omniAds__oas_columns undefined"><b>RUNNING</b></li>
<div class="omniAds__oas_columns"><a href="/my99acres/all_responses/OA"><b>16 Responses</b></a></div>
<li class="omniAds__oas_columns omniAds__oas_viewReportBtn" id="oas_viewReportBtn0">View Report</li>
</ul>
Solution
There is no method called Attribute
in Selenium-Python. It is get_attribute
Also, you should put some delay
time.sleep(5)
second_li = browser.find_element(By.XPATH,"//ul[@class='omniAds__oas_columnsWrapper']//following::li[2]").get_attribute('innerText')
print(second_li)
Recommendation (Use Explicit wait)
try:
second_li = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//ul[@class='omniAds__oas_columnsWrapper']//following::li[2]"))).get_attribute('innerText')
print(second_li)
except:
print("Could not get the text")
pass
You will have to import
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Answered By - cruisepandey
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.