Software Quality Assurance & Testing Asked on November 23, 2021
Hello please I’m quite a selenium newbie and I would need help for my thesis data.
I want to scrape this marketplace data https://www.tokopedia.com/search?st=shop&q=dapur
but to get the data that i want, i must go through pass some layers in the page.
In this case this web have 3 layers, First layers is the shop catalogue or the Starting url page:
(in this page users must click the "Lihat Toko" button to go to the next layer)
Second layers, is the Shop profile
(In this page users must click the "Info Toko" button to go to the final layer/pop up content)
Final layers, is the pop up content. I want to get the data from this pop up box
This is my code:
from selenium import webdriver
chrome_path = r"E:Chromedriverchromedriver.exe"
driver = webdriver.Chrome(chrome_path)
driver.get("https://www.tokopedia.com/search?st=shop&q=dapur")
driver.find_element_by_xpath('//div[@class="css-gmuwbf"]//button[1]').click()
driver.find_element_by_xpath('//div[@class="css-ais6tt"]//button[3]').click()
I’ve run the code but always have an error messages. A very big thank you for any suggest and advice.
I think you have to switch the window first then only you will be navigate to the second-page (layer):
please use below piece of code to switch your window :
public boolean switchToWindow(String windowname)
{
Set<String> windowsname=driver.getWindowHandles();
try {
windowsname.forEach(window->{
if(window.equalsIgnoreCase(windowname))
{
driver.switchTo().window(window);
}
});
return true;
}
catch(NoSuchWindowException e)
{
return false;
}
}
now please use the below piece of code to switch the alert and get the UIData :
public String getAlertData()
{
try {
WebDriverWait wait=new WebDriverWait(driver,30);
wait.until(ExpectedConditions.alertIsPresent());
Alert alert =driver.switchTo().alert();
return alert.getText();
}
catch(NoAlertPresentException e)
{
return null;
}
}
Answered by viren tiwari on November 23, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP