Home > Software engineering >  Logic to Capture the Data through Selnium Web driver - Python
Logic to Capture the Data through Selnium Web driver - Python

Time:09-17

I am Writing test case wherein i want to capture the data. That is when I click on the download button it shows the percentage progress i.e ( 1%, 2%, 3% and so on till 100%). I want to capture this text that is the Progress shown in the percentage(1%,2% and so on till 100%). I have tried and written the code but it is capturing only the start data i.e 0 and then 0% Below is the snap and code for your reference enter image description here

from selenium.webdriver.chrome.webdriver import WebDriver
from utilities.BaseClass import BaseClass
import pytest
from selenium import webdriver
from selenium.webdriver import ActionChains
import time
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By


driver = webdriver.Chrome(executable_path="C:\chromedriver")
driver.get("https://www.seleniumeasy.com/test/")
driver.maximize_window()
time.sleep(5)
driver.find_element_by_xpath("//a[text()='No, thanks!']").click() 
driver.execute_script("window.scrollTo(300, 500)")
driver.find_element_by_xpath("//a[contains(text(),'& Sliders')]").click()
driver.find_element_by_link_text("Bootstrap Progress bar").click()
driver.find_element_by_xpath("//button[@id='cricle-btn']").click()

percentage = driver.find_element_by_class_name("percenttext").text
percentage1 = []
for percent in percentage:
    percentage1.append(percent)
    print(percentage1)

time.sleep(21)
driver.close()

CodePudding user response:

Your code actually gets the element located by percenttext text one time only while you should get that element and extract it's text in a loop. Like this:

from selenium.webdriver.chrome.webdriver import WebDriver
from utilities.BaseClass import BaseClass
import pytest
from selenium import webdriver
from selenium.webdriver import ActionChains
import time
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By


driver = webdriver.Chrome(executable_path="C:\chromedriver")
driver.get("https://www.seleniumeasy.com/test/")
driver.maximize_window()
time.sleep(5)
driver.find_element_by_xpath("//a[text()='No, thanks!']").click() 
driver.execute_script("window.scrollTo(300, 500)")
driver.find_element_by_xpath("//a[contains(text(),'& Sliders')]").click()
driver.find_element_by_link_text("Bootstrap Progress bar").click()
driver.find_element_by_xpath("//button[@id='cricle-btn']").click()

percentage = driver.find_element_by_class_name("percenttext").text
while not '100%' in percentage:
    percentage = driver.find_element_by_class_name("percenttext").text    
    print(percentage)

time.sleep(21)
driver.close()
  • Related