Image not showing div class - python

When I insert an image on my html file it not showing on the page
index.html
<!-- start banner section -->
<section class="xs-banner-sec owl-carousel banner-slider">
<div class="banner-slider-item banner-item1" style="background-image: url(assets/images/banner-slider/banner_slider_1.jpg);">
<div class="slider-table">
<div class="slider-table-cell">
<div class="container">
<div class="row align-items-center">
<div class="col-lg-10 offset-lg-1">
<div class="banner-content text-center">
<h2>Best Gardening Service</h2>
<p>Wonderful serenity has taken possession of my entire soul, like these sweet mornings of spring
whole
heart.
</p>
and this is my folder

Does the div have a width or height? Divs will not take up space by default even with a background image as it isnt concidered content. Try giving it a height of 200px and a width of 200px just to test.

You should write background instead of background -image. cause it was not working for me until I changed it to background
<div class="banner-slider-item banner-item1" style="background: url(assets/images/banner-slider/banner_slider_1.jpg);">

Related

is there a method to detect common form in html code?

I have a lot of html pages that are formatted differently but the content that interests me is the same , for example :
Page_1.html :
<div class = "block_person">
<div class="persons"><span>Jules Rodrigez</span></div>
<div class="contents"><h1>Jules Rodrigez is a programmer specialized in machine learning</h1></div>
</div>
<div class = "block_person">
<div class="persons"><span>James Alfonso</span></div>
<div class="contents"><h1>James is a singer</h1></div>
</div>
page_2.html :
<div class="many_speakers" >
<div class="speakers"><h1>Jules Rodrigez</h1></div>
<div class="summary"><span>Jules Rodrigez is a programmer specialized in data science</span></div>
</div>
<div class="many_speakers" >
<div class="speakers"><h1>Peka Yaya</h1></div>
<div class="summary"><span>Peka is a professor</span></div>
</div>
<div class="many_speakers" >
<div class="speakers"><h1>Cristiano dimaria</h1></div>
<div class="summary"><span>Cristiano is a football player</span></div>
</div>
from a page html (page_1 or page_2), i want to get a list of objects like :
from page_1.html
[{"person":"Jules Rodrigez","content":"Jules Rodrigez is a programmer specialized in machine learning"},{"person":"James Alfonso","content":"James is a singer"}]
the problem is that each page is formatted with an structure : how can we detect in an html page that a block is repeated several times and therefore it contains the requested information : for example in the page_1.html the bloc which is repeated several times is :
<div class = "block_person">
<div class="persons"><span>Jules Rodrigez</span></div>
<div class="contents"><h1>Jules Rodrigez is a programmer specialized in machine learning</h1></div>
</div>

Selenium not finding element by link text

I try using
driver.find_element_by_partial_link_text('2019')
but I get an error saying it was unable to find the element. I also tried using find_element_by_link_text('') and using the whole line but it wont work.
Ideas?
driver.find_element_by_partial_link_text('2019').click()
That is what I have been trying with nothing working.
Here is the webpage HTML:
<div class="rowOf" id="tableRow1">
<div class="tableD">
<div class="productDiv" id="productDiv92195">
<h2 class="productTitle" id="productTitle92195" onclick="goToProduct(0)">2019 Wall Calendar by Camoleaf</h2>
<img class="productImage" src="https://images-na.ssl-images-amazon.com/images/I/91j3pmPYDOL.jpg" onclick="goToProduct(0)">
<hr>
<h4 class="normalPrice" id="normalPrice0" onclick="goToProduct(0)">
Normally: <span class="currency">$ </span>16.95
</h4>
<h4 class="promoPrice" style="margin:2.5px auto;" id="promoPrice92195" onclick="goToProduct(0)">
Your Amazon Price: <span class="currency">$ </span>1.70
</h4>
<h3>Your Total: <span class="currency">$ </span>1.70</h3>
<p class="clickToViewP" id="cToVP92195" onclick="goToProduct(0)">Click to view and purchase!</p>
</div>
</div>
<div class="tableD">
<div class="productDiv" id="productDiv69354">
<h2 class="productTitle" id="productTitle69354" onclick="goToProduct(1)">Pure Lyft Energy Drink Mix (4 Pack) by PURELYFT</h2>
<img class="productImage" src="https://images-na.ssl-images-amazon.com/images/I/81kCgs96Z0L.jpg" onclick="goToProduct(1)">
<hr>
<h4 class="normalPrice" id="normalPrice1" onclick="goToProduct(1)">
Normally: <span class="currency">$ </span>9.99
</h4>
<h4 class="promoPrice" style="margin:2.5px auto;" id="promoPrice69354" onclick="goToProduct(1)">
Your Amazon Price: <span class="currency">$ </span>0.99
</h4>
<h3>Your Total: <span class="currency">$ </span>0.99</h3>
<p class="clickToViewP" id="cToVP69354" onclick="goToProduct(1)">Click to view and purchase!</p>
</div>
</div>
<div class="tableD">
<div class="productDiv" id="productDiv79478">
<h2 class="productTitle" id="productTitle79478" onclick="goToProduct(2)">Multi-Purpose Calf Compression Sleeves by DS Sports</h2>
<img class="productImage" src="https://images-na.ssl-images-amazon.com/images/I/91U7ExY-SfL.jpg" onclick="goToProduct(2)">
<hr>
<h4 class="normalPrice" id="normalPrice2" onclick="goToProduct(2)">
Normally: <span class="currency">$ </span>12.95
</h4>
<h4 class="promoPrice" style="margin:2.5px auto;" id="promoPrice79478" onclick="goToProduct(2)">
Your Amazon Price: <span class="currency">$ </span>5.05
</h4>
<h3>Your Total: <span class="currency">$ </span>5.05</h3>
<p class="clickToViewP" id="cToVP79478" onclick="goToProduct(2)">Click to view and purchase!</p>
</div>
</div>
</div>
In your sample HTML, the only instance of "2019" is in an <h2> tag, not an anchor (<a>) link. Since find_element_by_partial_link_text() only searches anchor tags, it won't find it.
You can search via XPath to find an arbitrary element via partial text. Something like this:
all_matches = driver.find_elements_by_xpath("//*[text()[contains(., '2019')]]")
all_matches[0].click()
That XPath says:
Search all elements (*)
Look at each item's text() in turn
If that text() contains() the string "2019", add it to the set of matches.
And of course we only click on the first element that matches.
Instead of using driver.findElement(By.partialLinkText("2019"));
You should use driver.findElement(By.linkText("2019"));
This again won't work as there are many calander in which the link text is 2019. So you need to provide a particular name.
Example, I did this :-
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class AmazonShoping {
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver","C:\\Users\\priyj_kumar\\Downloads\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.amazon.in");
driver.findElement(By.id("twotabsearchtextbox")).sendKeys("2019 Calander",Keys.ENTER);
driver.findElement(By.linkText("mapyourmonth Planner Organizer Diary Wall Calendar 2019")).click();
//checking for a particular boat headphone say Boat BassHeads 900 Wired Headphone with Mic
// driver.findElement(By.linkText("Boat BassHeads 900 Wired Headphone with Mic")).click();
// String str = driver.findElement(By.xpath("//*[#id='mp-tfa']/p")).getText();
// System.out.println(str);
}
}
This worked fine for me. Please let me know if I misunderstood the question somehow.

Selenium clicking buttons by traversing through parent node

Need to exercise buttons ( edit / delete) in following HTML. Unique between all devices are "device-name". Hence locating target device is straight as -
cmd = "//div[#class='device-name' and text()='%s']" % (devicename)
element = brHandle.find_elements_by_xpath(cmd)
HTML -
<div class="device" id="device-1">..</div>
<div class="device" id="device-2">..</div>
<div class="device-form-factor desktop">
<div class="device-platform unknown"></div>
<div class="device-status">
....
</div>
</div>
<div class="device-name">auto-generated</div>
<div class="buttons">
<div class="button edit" href="#">Edit</div>
<div class="button delete" href="#">Delete</div>
</div>
</div>
<div class="device" id="device-3">..</div>
....
To access parent and then button, i tried following- but didn't work out. I was expecting to fetch device-id and then form my xpath to edit/delete button. Please suggest -
parent = element.find_element_by_xpath("..").text()

How to download all images under one specific node in Scrapy?

I am using Scrapy, I want to download all images under one node, for example, here is the web page:
<!-- language: lang-xml -->
<div class="A">
<div class="A1">
<div class="A2">
<img original="a1.png"></img>
</div>
</div>
<div class="A3">
<img original="a2.png"></img>
</div>
</div>
<div class="B">
<div class="B1">
<div class="B2">
<img original="b1.png"></img>
</div>
</div>
<div class="B3">
<img original="b2.png"></img>
</div>
</div>
I want to download all images (I need to find the original urls for these images) under class="A" but not class="B", and under class="A" we have a1.png and a2.png, they are at different levels (the number of level is uncertain).
Is there any way to target one attribute under one specific node using XPATH (something like //div[#class="A"]/**/img ) ?
or is there any solution in Scrapy?
Using the following XPath to select all img nodes that are descendants of a div node with class A:
//div[#class="A"]//img
Demo
The // matches descendants, as opposed to /, which matches direct children.

Follow a sibling in Selenium/Python

I want to enter a text in a text area. The HTML code is as follows:
<li class="order-unavailable string-type-key string-block clear-fix status- require_changes expanded working autogrowed activity-opened" data-string_status="require_changes" data-master_unit_count="22" data-string_id="2394473">
<div class="key-area clear-fix">
<div class="key-area-container-one clear-fix">
<div class="key-area-container-two">
<div class="col-50 col-left">
<div class="string-controls">
<a class="control-expand-toggle selected" href="#"></a>
<a class="control-activity-toggle " href="#">2</a>
<input class="control-select-string" type="checkbox">
</div>
<div class="master-content">
</div>
<div class="col-50 col-right slave-side-container">
</div>
</div>
</div>
<div class="activity-area clear-fix">
<div class="col-50 col-left">
<div class="col-50 col-right">
<div class="comment-area-inner">
<h3>Add comment</h3>
<div class="comment-container">
<textarea class="comment-content" name="comment_content"></textarea>
</div>
<div class="col-right">
<div class="clear"></div>
<strong>Notification settings</strong>
<p>The people you select will get an email when you post this comment. They'll also be notified by email every time a new comment is added.</p>
<div class="notification-settings">
</div>
</div>
</div>
The textarea component name is comment-content
The xpath of the textarea is:
/html/body/div/section/ol/li[16]/div[2]/div[2]/div/div/textarea
This is the code I am using:
driver.find_element_by_xpath("*//div[#title=\"NOTIFICATION_HOMEPAGE_REDIRECT_CHANGED_SITE\"]
/following-sibling::div[2]/div[2]/div/div/textarea").send_keys("Test comment")
Can someone hekp me how to frame the sibling tag?
div[2]/div[2]/div/div/textarea
The tag before the following-sibling keyword is correct.
Choose the textarea and enter something,
driver.find_element_by_xpath(r'//textarea[#class='comment-content']').send_keys('Test Comment')
For xpath, you can use tool Firepath plugin for Firefox

Categories