0

I would like to get the contact details (email and phone numbers) of the seller.

[<ul class="_17qy1 _1rj80 _1sql3 _3a4zn"><li><a class="_w7z6o" data-box-name="AskSellerClick" href="#zadaj-pytanie" rel="nofollow">pytanie do sprzedającego</a></li><li><div>pjp*******@******<!-- --> (<button class="_w7z6o _ypulx" data-box-name="SellerEmailShow" type="button">pokaż</button>)</div></li></ul>, <ul class="_17qy1 _1rj80 _1sql3 _3a4zn"><li><div>+48 *** *** ***<!-- --> (<button class="_w7z6o _ypulx" data-box-name="SellerMobileShow" type="button">pokaż</button>)</div></li></ul>]

The following did not work:

click_on_button = wd.find_elements(By.CLASS_NAME, 'SellerMobileShow')

click_on_button = wd.find_elements_by_css_selector('body > div.main-wrapper > div:nth-child(3) > div > div > div:nth-child(10) > div > div > div > div > div:nth-child(5) > div:nth-child(2) > div > div > div._t2hyt._l7nkx._r6475._1rcax._nyhhx._1bo4a._r8zxu._1ar9d._62fe8_pdZjg._62fe8_CY37T._62fe8_24sRD > div > div._9f0v0._1xzdi._ai5yc._5d6n2._1h7wt._62fe8_1ibzI > section > div > div > div > div:nth-child(2) > div > div > div._1bo4a._xu6h2._m7qxj._1q55c > section:nth-child(2) > div > div > div:nth-child(2) > ul > li:nth-child(1) > div > button')

find_element_by_xpath('/html/body/div[2]/div[3]/div/div/div[10]/div/div/div/div/div[5]/div[2]/div/div/div[2]/div/div[2]/section/div/div/div/div[2]/div/div/div[2]/section[2]/div/div/div[1]/ul/li[2]/div/button')

When the auction link changes, does the Xpath copied from Chrome or CSS Selector stop working? How will the relarive Xpath be determined or how else can you click on these three buttons to see the seller's data?

https://allegro.pl/oferta/faller-170601-plyta-dekoracyjna-droga-brukowana-h0-9303217744#aboutSeller

2 Answers 2

1
email = driver.find_element_by_xpath("//*[@data-box-name=\"SellerEmailShow\"]/..")
print(email.text)
phone = driver.find_element_by_xpath("//*[@data-box-name=\"SellerMobileShow\"]/..")
print(phone.text)

You can use button as reference

you can use explicit wait if timing issues occurs

email = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located(
        (By.XPATH, "//*[@data-box-name=\"SellerEmailShow\"]/.."))
)
Sign up to request clarification or add additional context in comments.

3 Comments

click on the button doesn't work, the code: click_on_button = wd.find_element_by_xpath("//*[@data-box-name='SellerEmailShow']/..") click_on_button.click() return: pjp*******@****** (pokaż) +48 *** *** *** (pokaż) +48 *** *** *** (pokaż)
@dominik driver.find_element_by_xpath("//*[@data-box-name=\"SellerEmailShow\"]").click() , you have to use this to click and then use the code given
your expression doesn't find the matching element, so I changing it to: click_on_button = wd.find_element_by_xpath("//*[@data-box-name='SellerEmailShow']/..") click_on_button.click() print(click_on_button.text) console: pjp*******@****** (pokaż) How to deal with it?
0

To print the texts you need to induce WebDriverWait for the visibility_of_element_located() you can use the following based Locator Strategies:

  • Printing pjp*******@****** (pokaż):

    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//a[contains(., 'pytanie do sprzedającego')]//following::li[1]/div"))).text)
    
  • Printing +48 *** *** *** (pokaż):

    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//a[contains(., 'pytanie do sprzedającego')]//following::li[2]/div"))).text)
    

Update

To print the full email and phone i.e. [email protected] and +48 501 433 898 you can use the following based Locator Strategies:

  • Code Block:

    driver.get("https://allegro.pl/oferta/faller-170601-plyta-dekoracyjna-droga-brukowana-h0-9303217744#aboutSeller")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@data-role='accept-consent']"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@data-box-name='SellerEmailShow']"))).click()
    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//a[@data-box-name='SellerEmailClick']"))).text)
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@data-box-name='SellerMobileShow']"))).click()
    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//li[.//a[@data-box-name='SellerEmailClick']]//following::li[1]/div"))).text)
    
  • Console Output:

    [email protected]
    +48 501 433 898
    

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.