Skip to content
Advertisement

Trying to select the option

import time
from playwright.sync_api import sync_playwright
import pandas as pd

with sync_playwright() as p:
    browser = p.webkit.launch(headless=False)
    baseurl = "https://www.ifep.ro/justice/lawyers/lawyerspanel.aspx"
    page = browser.new_page()
    page.goto(baseurl)
    productlinks = []
    for k in range(1, 2450):
        links = page.query_selector_all("//div[@class='list-group']//a")
        for link in links:
            link_href = link.get_attribute("href")
            if link_href.startswith("LawyerFile.aspx"):
                productlinks.append("https://www.ifep.ro/justice/lawyers/" + link_href)
              
        dropdown=page.wait_for_selector("#MainContent_ddlRecords")
        dropdown.selectOption({"label": "30"})      
        time.sleep(5)
        page.wait_for_selector("#MainContent_PagerTop_NavNext").click()
        time.sleep(2)  # wait for load the page
    data=[]    
    for product in productlinks:
        wev={}
        page.goto(product)
        title = page.wait_for_selector('#HeadingContent_lblTitle').text_content()
        wev['title']=title
        d1 = page.wait_for_selector("//div[@class='col-md-10']//p[1]").text_content()
        d1 = d1.strip().split()[-1]
        d6=page.wait_for_selector("//span[@class='text-nowrap']//a").text_content()
        wev['Email']=d6
        d5 = page.wait_for_selector("//span[@class='padding-right-md text-primary']").text_content()
        d5=d5.replace(".", "")
        wev['phone']=d5
        wev['Avocat Definitiv']=d1
        d2 = page.wait_for_selector("//div[@class='col-md-10']//p[2]").text_content()
        d2 = d2.strip().split()[-1]
        wev['Dată înscriere']=d2
        d3 = page.wait_for_selector("//div[@class='col-md-10']//p[3]//span").text_content()
        d3 = d3.strip().split()[-1]
        wev['Situaţie curentă în tablou']=d3
        d4 = page.wait_for_selector("//div[@class='col-md-10']//p[4]").text_content()
        d4 = d4.strip().split()[-1]
        wev['Instanţe cu drept de concluzii']=d4
        data.append(wev) 
        
    df=pd.DataFrame(data)
    df.to_csv("test.csv")
    browser.close()

I want to click these option on the pages is there any I am new to a playwright I am not familiar with playwrights so much kindly any solution recommended these is page link https://www.ifep.ro/justice/lawyers/lawyerspanel.aspx

enter image description here

Advertisement

Answer

You can use the select_options for selecting 30.

page.select_option('select#MainContent_ddlRecords', '30')

You can use the text selector and then click the checkboxes like this:

page.locator("text=Tabloul avocaţilor stagiari").click()
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement